diff --git a/.yarn/versions/4c56dfd7.yml b/.yarn/versions/4c56dfd7.yml new file mode 100644 index 00000000..85470d2c --- /dev/null +++ b/.yarn/versions/4c56dfd7.yml @@ -0,0 +1,4 @@ +releases: + "@solarwinds-apm/instrumentations": major + "@solarwinds-apm/sdk": minor + solarwinds-apm: major diff --git a/packages/instrumentations/src/compatibility.ts b/packages/instrumentations/src/compatibility.ts index 54684337..f53b63a0 100644 --- a/packages/instrumentations/src/compatibility.ts +++ b/packages/instrumentations/src/compatibility.ts @@ -26,7 +26,7 @@ import { type Comparator, compare, minVersion, Range } from "semver" import { getInstrumentations } from "./index.js" -const instrumentations = getInstrumentations() as InstrumentationBase[] +const instrumentations = getInstrumentations({}, false) as InstrumentationBase[] const init = "init" as const const definitions = instrumentations diff --git a/packages/instrumentations/src/index.ts b/packages/instrumentations/src/index.ts index 178d91de..ce15db88 100644 --- a/packages/instrumentations/src/index.ts +++ b/packages/instrumentations/src/index.ts @@ -119,7 +119,8 @@ export type InstrumentationConfigMap = { } export function getInstrumentations( - configs: InstrumentationConfigMap = {}, + configs: InstrumentationConfigMap, + defaultDisabled: boolean, ): Instrumentation[] { const instrumentations: Instrumentation[] = [] const c: Record = configs @@ -127,7 +128,9 @@ export function getInstrumentations( for (const [name, Class] of Object.entries< new (config?: InstrumentationConfig) => Instrumentation >(INSTRUMENTATIONS)) { - const config = c[name] + let config = c[name] + + if (defaultDisabled) (config ??= {}).enabled ??= false if (config?.enabled === false) continue instrumentations.push(new Class(config)) diff --git a/packages/sdk/src/patches/lambda.ts b/packages/sdk/src/patches/aws-lambda.ts similarity index 100% rename from packages/sdk/src/patches/lambda.ts rename to packages/sdk/src/patches/aws-lambda.ts diff --git a/packages/sdk/src/patches/aws-sdk.ts b/packages/sdk/src/patches/aws-sdk.ts new file mode 100644 index 00000000..44cf3486 --- /dev/null +++ b/packages/sdk/src/patches/aws-sdk.ts @@ -0,0 +1,25 @@ +/* +Copyright 2023-2024 SolarWinds Worldwide, LLC. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +import { type InstrumentationConfig } from "@opentelemetry/instrumentation" +import { IS_AWS_LAMBDA } from "@solarwinds-apm/module" + +import { type Patch } from "." + +export const patch: Patch = (config) => ({ + ...config, + enabled: config.enabled ?? (IS_AWS_LAMBDA || undefined), +}) diff --git a/packages/sdk/src/patches/index.ts b/packages/sdk/src/patches/index.ts index 976b7fc4..ca872929 100644 --- a/packages/sdk/src/patches/index.ts +++ b/packages/sdk/src/patches/index.ts @@ -27,10 +27,11 @@ import { type TextMapPropagator } from "@opentelemetry/api" import { type InstrumentationConfig } from "@opentelemetry/instrumentation" import { type SwConfiguration } from "../config" +import * as awsLambda from "./aws-lambda" +import * as awsSdk from "./aws-sdk" import * as bunyan from "./bunyan" import * as fs from "./fs" import * as http from "./http" -import * as lambda from "./lambda" import * as mysql2 from "./mysql2" import * as pg from "./pg" import * as pino from "./pino" @@ -48,7 +49,8 @@ export type Patch = ( export const RESOURCE_SERVICE_NAME = "resource.service.name" as const const patches = { - "aws-lambda": lambda, + "aws-lambda": awsLambda, + "aws-sdk": awsSdk, bunyan, fs, http, diff --git a/packages/solarwinds-apm/src/config.ts b/packages/solarwinds-apm/src/config.ts index 8c3503f2..1f74ab88 100644 --- a/packages/solarwinds-apm/src/config.ts +++ b/packages/solarwinds-apm/src/config.ts @@ -166,6 +166,7 @@ const schema = z.object({ swMetrics: boolean.default(!IS_SERVERLESS), initMessage: boolean.default(!IS_SERVERLESS), resourceDetection: boolean.default(true), + instrumentationsDefaultDisabled: boolean.default(IS_SERVERLESS), }) .default({}), }) diff --git a/packages/solarwinds-apm/src/init.ts b/packages/solarwinds-apm/src/init.ts index bed148dd..02f99126 100644 --- a/packages/solarwinds-apm/src/init.ts +++ b/packages/solarwinds-apm/src/init.ts @@ -131,6 +131,7 @@ function initInstrumentations(config: ExtendedSwConfiguration) { ...config, responsePropagator: traceOptionsResponsePropagator, }), + config.dev.instrumentationsDefaultDisabled, ), ...(config.instrumentations.extra ?? []), ] diff --git a/packages/solarwinds-apm/test/config.test.ts b/packages/solarwinds-apm/test/config.test.ts index d8f3dd3e..076b31f7 100644 --- a/packages/solarwinds-apm/test/config.test.ts +++ b/packages/solarwinds-apm/test/config.test.ts @@ -53,6 +53,7 @@ describe("readConfig", () => { swMetrics: true, initMessage: true, resourceDetection: true, + instrumentationsDefaultDisabled: false, }, }