Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(nodejs): configureAwsInstrumentation for downstream #1375

Merged
merged 3 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions nodejs/packages/layer/.mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"require": "ts-node/register",
"spec": ["test/**/*.spec.ts"]
}
10 changes: 9 additions & 1 deletion nodejs/packages/layer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"lint:fix": "ESLINT_USE_FLAT_CONFIG=false eslint . --ext .ts --fix",
"prepare": "npm run compile",
"compile": "tsc -p .",
"postcompile": "copyfiles 'node_modules/**' build/workspace/nodejs && copyfiles -f 'scripts/*' build/workspace && copyfiles -f 'build/src/*' build/workspace && cd build/workspace && bestzip ../layer.zip *"
"postcompile": "copyfiles 'node_modules/**' build/workspace/nodejs && copyfiles -f 'scripts/*' build/workspace && copyfiles -f 'build/src/*' build/workspace && cd build/workspace && bestzip ../layer.zip *",
"test": "mocha"
},
"keywords": [
"opentelemetry",
Expand Down Expand Up @@ -51,5 +52,12 @@
"@opentelemetry/sdk-metrics": "^1.18.1",
"@opentelemetry/sdk-trace-base": "^1.18.1",
"@opentelemetry/sdk-trace-node": "^1.18.1"
},
"devDependencies": {
"@types/mocha": "^10.0.6",
"@types/sinon": "^17.0.3",
"mocha": "^10.4.0",
"sinon": "^18.0.0",
"ts-node": "^10.9.2"
}
}
11 changes: 7 additions & 4 deletions nodejs/packages/layer/src/wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
envDetector,
processDetector,
} from '@opentelemetry/resources';
import { AwsInstrumentation } from '@opentelemetry/instrumentation-aws-sdk';
import { AwsInstrumentation, AwsSdkInstrumentationConfig } from '@opentelemetry/instrumentation-aws-sdk';
import { AwsLambdaInstrumentation } from '@opentelemetry/instrumentation-aws-lambda';
import {
diag,
Expand Down Expand Up @@ -58,6 +58,7 @@ function defaultConfigureInstrumentations() {

declare global {
// in case of downstream configuring span processors etc
function configureAwsInstrumentation(defaultConfig: AwsSdkInstrumentationConfig): AwsSdkInstrumentationConfig
function configureTracerProvider(tracerProvider: NodeTracerProvider): void
function configureTracer(defaultConfig: NodeTracerConfig): NodeTracerConfig;
function configureSdkRegistration(
Expand All @@ -72,9 +73,11 @@ declare global {
console.log('Registering OpenTelemetry');

const instrumentations = [
new AwsInstrumentation({
suppressInternalInstrumentation: true,
}),
new AwsInstrumentation(
typeof configureAwsInstrumentation === 'function'
? configureAwsInstrumentation({suppressInternalInstrumentation: true})
: {suppressInternalInstrumentation: true,},
),
new AwsLambdaInstrumentation(typeof configureLambdaInstrumentation === 'function' ? configureLambdaInstrumentation({}) : {}),
...(typeof configureInstrumentations === 'function' ? configureInstrumentations: defaultConfigureInstrumentations)()
];
Expand Down
23 changes: 23 additions & 0 deletions nodejs/packages/layer/test/wrapper.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { AwsSdkInstrumentationConfig } from "@opentelemetry/instrumentation-aws-sdk";
import { stub } from "sinon";

declare global {
function configureAwsInstrumentation(
defaultConfig: AwsSdkInstrumentationConfig,
): AwsSdkInstrumentationConfig;
}

const assert = require("assert");

describe("wrapper", () => {
describe("configureAwsInstrumentation", () => {
it("is used if defined", () => {
const configureAwsInstrumentationStub = stub().returns({
suppressInternalInstrumentation: true,
});
global.configureAwsInstrumentation = configureAwsInstrumentationStub;
require("../src/wrapper");
assert(configureAwsInstrumentationStub.calledOnce);
}).timeout(10000);
});
});
Loading