Skip to content

Commit 4fa2feb

Browse files
committed
upgrade otel version, remove patches that are not needed anymore
1 parent a041769 commit 4fa2feb

File tree

17 files changed

+7751
-3165
lines changed

17 files changed

+7751
-3165
lines changed

aws-distro-opentelemetry-node-autoinstrumentation/package.json

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
"@aws-sdk/client-secrets-manager": "^3.632.0",
8080
"@aws-sdk/client-sfn": "^3.632.0",
8181
"@aws-sdk/client-sns": "^3.632.0",
82-
"@opentelemetry/contrib-test-utils": "0.41.0",
82+
"@opentelemetry/contrib-test-utils": "^0.45.0",
8383
"@smithy/protocol-http": "^5.0.1",
8484
"@smithy/signature-v4": "^5.0.1",
8585
"@types/mocha": "7.0.2",
@@ -98,24 +98,24 @@
9898
},
9999
"dependencies": {
100100
"@opentelemetry/api": "1.9.0",
101-
"@opentelemetry/auto-configuration-propagators": "0.3.0",
102-
"@opentelemetry/auto-instrumentations-node": "0.50.0",
103-
"@opentelemetry/core": "1.26.0",
104-
"@opentelemetry/exporter-metrics-otlp-grpc": "0.53.0",
105-
"@opentelemetry/exporter-metrics-otlp-http": "0.53.0",
106-
"@opentelemetry/exporter-trace-otlp-proto": "0.53.0",
107-
"@opentelemetry/exporter-zipkin": "1.26.0",
108-
"@opentelemetry/id-generator-aws-xray": "1.2.2",
109-
"@opentelemetry/instrumentation": "0.53.0",
110-
"@opentelemetry/instrumentation-aws-sdk": "0.44.0",
111-
"@opentelemetry/otlp-transformer": "0.53.0",
112-
"@opentelemetry/propagator-aws-xray": "1.26.0",
113-
"@opentelemetry/resource-detector-aws": "1.6.1",
114-
"@opentelemetry/resources": "1.26.0",
115-
"@opentelemetry/sdk-metrics": "1.26.0",
116-
"@opentelemetry/sdk-node": "0.53.0",
117-
"@opentelemetry/sdk-trace-base": "1.26.0",
118-
"@opentelemetry/semantic-conventions": "1.27.0"
101+
"@opentelemetry/auto-configuration-propagators": "0.3.2",
102+
"@opentelemetry/auto-instrumentations-node": "0.56.0",
103+
"@opentelemetry/core": "1.30.1",
104+
"@opentelemetry/exporter-metrics-otlp-grpc": "0.57.1",
105+
"@opentelemetry/exporter-metrics-otlp-http": "0.57.1",
106+
"@opentelemetry/exporter-trace-otlp-proto": "0.57.1",
107+
"@opentelemetry/exporter-zipkin": "1.30.1",
108+
"@opentelemetry/id-generator-aws-xray": "1.2.3",
109+
"@opentelemetry/instrumentation": "0.57.1",
110+
"@opentelemetry/instrumentation-aws-sdk": "0.49.0",
111+
"@opentelemetry/otlp-transformer": "0.57.1",
112+
"@opentelemetry/propagator-aws-xray": "1.26.2",
113+
"@opentelemetry/resource-detector-aws": "1.12.0",
114+
"@opentelemetry/resources": "1.30.1",
115+
"@opentelemetry/sdk-metrics": "1.30.1",
116+
"@opentelemetry/sdk-node": "0.57.1",
117+
"@opentelemetry/sdk-trace-base": "1.30.1",
118+
"@opentelemetry/semantic-conventions": "1.28.0"
119119
},
120120
"files": [
121121
"build/src/**/*.js",

aws-distro-opentelemetry-node-autoinstrumentation/src/otlp-aws-span-exporter.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class OTLPAwsSpanExporter extends OTLPProtoTraceExporter {
5656
This is bad practice but there is no other way to access and inject SigV4 headers
5757
into the request headers before the traces get exported.
5858
*/
59-
const oldHeaders = (this as any)._transport?._transport?._parameters?.headers;
59+
const oldHeaders = (this as any)._delegate._transport?._transport?._parameters?.headers;
6060

6161
if (oldHeaders) {
6262
const request = new this.httpRequest({
@@ -81,7 +81,7 @@ export class OTLPAwsSpanExporter extends OTLPProtoTraceExporter {
8181

8282
const signedRequest = await signer.sign(request);
8383

84-
(this as any)._transport._transport._parameters.headers = signedRequest.headers;
84+
(this as any)._delegate._transport._transport._parameters.headers = signedRequest.headers;
8585
} catch (exception) {
8686
diag.debug(
8787
`Failed to sign/authenticate the given exported Span request to OTLP XRay endpoint with error: ${exception}`
@@ -128,9 +128,9 @@ export class OTLPAwsSpanExporter extends OTLPProtoTraceExporter {
128128
}
129129
}
130130

131-
private static changeUrlConfig(endpoint: string, config?: OTLPExporterNodeConfigBase) {
131+
private static changeUrlConfig(endpoint: string, config?: OTLPExporterNodeConfigBase): OTLPExporterNodeConfigBase {
132132
const newConfig =
133-
config === undefined
133+
config == null
134134
? { url: endpoint }
135135
: {
136136
...config,

aws-distro-opentelemetry-node-autoinstrumentation/src/patches/aws/services/kinesis.ts

Lines changed: 0 additions & 41 deletions
This file was deleted.

aws-distro-opentelemetry-node-autoinstrumentation/src/patches/aws/services/s3.ts

Lines changed: 0 additions & 41 deletions
This file was deleted.

aws-distro-opentelemetry-node-autoinstrumentation/src/patches/extended-instrumentations/aws-lambda.ts

Lines changed: 0 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -3,123 +3,11 @@
33
// Modifications Copyright The OpenTelemetry Authors. Licensed under the Apache License 2.0 License.
44

55
import { AwsLambdaInstrumentation } from '@opentelemetry/instrumentation-aws-lambda';
6-
import * as path from 'path';
7-
import * as fs from 'fs';
8-
import {
9-
InstrumentationNodeModuleDefinition,
10-
InstrumentationNodeModuleFile,
11-
isWrapped,
12-
} from '@opentelemetry/instrumentation';
136
import { diag, Span, SpanStatusCode } from '@opentelemetry/api';
147

158
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
169
// @ts-ignore
1710
export class AwsLambdaInstrumentationPatch extends AwsLambdaInstrumentation {
18-
override init() {
19-
// Custom logic before calling the original implementation
20-
diag.debug('Initializing AwsLambdaInstrumentationPatch');
21-
const taskRoot = process.env.LAMBDA_TASK_ROOT;
22-
const handlerDef = this._config.lambdaHandler ?? process.env._HANDLER;
23-
24-
// _HANDLER and LAMBDA_TASK_ROOT are always defined in Lambda but guard bail out if in the future this changes.
25-
if (!taskRoot || !handlerDef) {
26-
this._diag.debug('Skipping lambda instrumentation: no _HANDLER/lambdaHandler or LAMBDA_TASK_ROOT.', {
27-
taskRoot,
28-
handlerDef,
29-
});
30-
return [];
31-
}
32-
33-
const handler = path.basename(handlerDef);
34-
const moduleRoot = handlerDef.substr(0, handlerDef.length - handler.length);
35-
36-
const [module, functionName] = handler.split('.', 2);
37-
38-
// Lambda loads user function using an absolute path.
39-
let filename = path.resolve(taskRoot, moduleRoot, module);
40-
if (!filename.endsWith('.js')) {
41-
// its impossible to know in advance if the user has a cjs or js or mjs file.
42-
// check that the .js file exists otherwise fallback to next known possibility
43-
try {
44-
fs.statSync(`${filename}.js`);
45-
filename += '.js';
46-
} catch (e) {
47-
// fallback to .cjs
48-
try {
49-
fs.statSync(`${filename}.cjs`);
50-
filename += '.cjs';
51-
} catch (e) {
52-
// fall back to .mjs
53-
filename += '.mjs';
54-
}
55-
}
56-
}
57-
58-
diag.debug('Instrumenting lambda handler', {
59-
taskRoot,
60-
handlerDef,
61-
handler,
62-
moduleRoot,
63-
module,
64-
filename,
65-
functionName,
66-
});
67-
68-
if (filename.endsWith('.mjs') || process.env.HANDLER_IS_ESM) {
69-
return [
70-
new InstrumentationNodeModuleDefinition(
71-
// NB: The patching infrastructure seems to match names backwards, this must be the filename, while
72-
// InstrumentationNodeModuleFile must be the module name.
73-
filename,
74-
['*'],
75-
(moduleExports: any) => {
76-
diag.debug('Applying patch for lambda esm handler');
77-
if (isWrapped(moduleExports[functionName])) {
78-
this._unwrap(moduleExports, functionName);
79-
}
80-
this._wrap(moduleExports, functionName, (this as any)._getHandler());
81-
return moduleExports;
82-
},
83-
(moduleExports?: any) => {
84-
if (moduleExports == null) return;
85-
diag.debug('Removing patch for lambda esm handler');
86-
this._unwrap(moduleExports, functionName);
87-
}
88-
),
89-
];
90-
} else {
91-
return [
92-
new InstrumentationNodeModuleDefinition(
93-
// NB: The patching infrastructure seems to match names backwards, this must be the filename, while
94-
// InstrumentationNodeModuleFile must be the module name.
95-
filename,
96-
['*'],
97-
undefined,
98-
undefined,
99-
[
100-
new InstrumentationNodeModuleFile(
101-
module,
102-
['*'],
103-
(moduleExports: any) => {
104-
diag.debug('Applying patch for lambda handler');
105-
if (isWrapped(moduleExports[functionName])) {
106-
this._unwrap(moduleExports, functionName);
107-
}
108-
this._wrap(moduleExports, functionName, (this as any)._getHandler());
109-
return moduleExports;
110-
},
111-
(moduleExports?: any) => {
112-
if (moduleExports == null) return;
113-
diag.debug('Removing patch for lambda handler');
114-
this._unwrap(moduleExports, functionName);
115-
}
116-
),
117-
]
118-
),
119-
];
120-
}
121-
}
122-
12311
// Override the upstream private _endSpan method to remove the unnecessary metric force-flush error message
12412
// https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/plugins/node/opentelemetry-instrumentation-aws-lambda/src/instrumentation.ts#L358-L398
12513
override _endSpan(span: Span, err: string | Error | null | undefined, callback: () => void) {

aws-distro-opentelemetry-node-autoinstrumentation/src/patches/instrumentation-patch.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ import {
2929
BedrockRuntimeServiceExtension,
3030
BedrockServiceExtension,
3131
} from './aws/services/bedrock';
32-
import { KinesisServiceExtension } from './aws/services/kinesis';
33-
import { S3ServiceExtension } from './aws/services/s3';
3432
import { SecretsManagerServiceExtension } from './aws/services/secretsmanager';
3533
import { StepFunctionsServiceExtension } from './aws/services/step-functions';
3634
import { InstrumentationConfigMap } from '@opentelemetry/auto-instrumentations-node';
@@ -74,8 +72,6 @@ export function applyInstrumentationPatches(
7472
const services: Map<string, ServiceExtension> | undefined = (instrumentations[index] as any).servicesExtensions
7573
?.services;
7674
if (services) {
77-
services.set('S3', new S3ServiceExtension());
78-
services.set('Kinesis', new KinesisServiceExtension());
7975
services.set('SecretsManager', new SecretsManagerServiceExtension());
8076
services.set('SFN', new StepFunctionsServiceExtension());
8177
services.set('Bedrock', new BedrockServiceExtension());
@@ -90,7 +86,6 @@ export function applyInstrumentationPatches(
9086
diag.debug('Overriding aws lambda instrumentation');
9187
const lambdaInstrumentation = new AwsLambdaInstrumentationPatch({
9288
eventContextExtractor: customExtractor,
93-
disableAwsContextPropagation: true,
9489
});
9590
instrumentations[index] = lambdaInstrumentation;
9691
}

aws-distro-opentelemetry-node-autoinstrumentation/test/aws-opentelemetry-configurator.test.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -319,25 +319,29 @@ describe('AwsOpenTelemetryConfiguratorTest', () => {
319319
// Check default protocol - HTTP, as specified by aws-distro-opentelemetry-node-autoinstrumentation's register.ts.
320320
let exporter: PushMetricExporter = ApplicationSignalsExporterProvider.Instance.createExporter();
321321
expect(exporter).toBeInstanceOf(OTLPHttpOTLPMetricExporter);
322-
expect('http://localhost:4316/v1/metrics').toEqual((exporter as any)._otlpExporter.url);
322+
expect('http://localhost:4316/v1/metrics').toEqual(
323+
(exporter as any)._delegate._transport._transport._parameters.url
324+
);
323325

324326
// Overwrite protocol to gRPC.
325327
process.env.OTEL_EXPORTER_OTLP_PROTOCOL = 'grpc';
326328
exporter = ApplicationSignalsExporterProvider.Instance.createExporter();
327329
expect(exporter).toBeInstanceOf(OTLPGrpcOTLPMetricExporter);
328-
expect('localhost:4315').toEqual((exporter as any)._otlpExporter.url);
330+
expect('localhost:4315').toEqual((exporter as any)._delegate._transport._parameters.address);
329331

330332
// Overwrite protocol back to HTTP.
331333
process.env.OTEL_EXPORTER_OTLP_PROTOCOL = 'http/protobuf';
332334
exporter = ApplicationSignalsExporterProvider.Instance.createExporter();
333335
expect(exporter).toBeInstanceOf(OTLPHttpOTLPMetricExporter);
334-
expect('http://localhost:4316/v1/metrics').toEqual((exporter as any)._otlpExporter.url);
336+
expect('http://localhost:4316/v1/metrics').toEqual(
337+
(exporter as any)._delegate._transport._transport._parameters.url
338+
);
335339

336340
// If for some reason, the env var is undefined (it shouldn't), overwrite protocol to gRPC.
337341
delete process.env.OTEL_EXPORTER_OTLP_PROTOCOL;
338342
exporter = ApplicationSignalsExporterProvider.Instance.createExporter();
339343
expect(exporter).toBeInstanceOf(OTLPGrpcOTLPMetricExporter);
340-
expect('localhost:4315').toEqual((exporter as any)._otlpExporter.url);
344+
expect('localhost:4315').toEqual((exporter as any)._delegate._transport._parameters.address);
341345

342346
// Expect invalid protocol to throw error.
343347
process.env.OTEL_EXPORTER_OTLP_PROTOCOL = 'invalid_protocol';
@@ -351,38 +355,42 @@ describe('AwsOpenTelemetryConfiguratorTest', () => {
351355
// Check default protocol - HTTP, as specified by aws-distro-opentelemetry-node-autoinstrumentation's register.ts.
352356
exporter = ApplicationSignalsExporterProvider.Instance.createExporter();
353357
expect(exporter).toBeInstanceOf(OTLPHttpOTLPMetricExporter);
354-
expect('http://localhost:4316/v1/metrics').toEqual((exporter as any)._otlpExporter.url);
358+
expect('http://localhost:4316/v1/metrics').toEqual(
359+
(exporter as any)._delegate._transport._transport._parameters.url
360+
);
355361

356362
// Overwrite protocol to gRPC.
357363
process.env.OTEL_EXPORTER_OTLP_METRICS_PROTOCOL = 'grpc';
358364
exporter = ApplicationSignalsExporterProvider.Instance.createExporter();
359365
expect(exporter).toBeInstanceOf(OTLPGrpcOTLPMetricExporter);
360-
expect('localhost:4315').toEqual((exporter as any)._otlpExporter.url);
366+
expect('localhost:4315').toEqual((exporter as any)._delegate._transport._parameters.address);
361367

362368
// Overwrite protocol back to HTTP.
363369
process.env.OTEL_EXPORTER_OTLP_METRICS_PROTOCOL = 'http/protobuf';
364370
exporter = ApplicationSignalsExporterProvider.Instance.createExporter();
365371
expect(exporter).toBeInstanceOf(OTLPHttpOTLPMetricExporter);
366-
expect('http://localhost:4316/v1/metrics').toEqual((exporter as any)._otlpExporter.url);
372+
expect('http://localhost:4316/v1/metrics').toEqual(
373+
(exporter as any)._delegate._transport._transport._parameters.url
374+
);
367375

368376
// Expect invalid protocol to throw error.
369377
process.env.OTEL_EXPORTER_OTLP_METRICS_PROTOCOL = 'invalid_protocol';
370378
expect(() => ApplicationSignalsExporterProvider.Instance.createExporter()).toThrow();
371379

372380
// Test custom URLs via OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT
373-
process.env.OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT = 'my_custom_endpoint';
381+
process.env.OTEL_AWS_APPLICATION_SIGNALS_EXPORTER_ENDPOINT = 'http://my_custom_endpoint';
374382

375383
// Overwrite protocol to gRPC, export to url "my_custom_endpoint"
376384
process.env.OTEL_EXPORTER_OTLP_METRICS_PROTOCOL = 'grpc';
377385
exporter = ApplicationSignalsExporterProvider.Instance.createExporter();
378386
expect(exporter).toBeInstanceOf(OTLPGrpcOTLPMetricExporter);
379-
expect('my_custom_endpoint').toEqual((exporter as any)._otlpExporter.url);
387+
expect('my_custom_endpoint').toEqual((exporter as any)._delegate._transport._parameters.address);
380388

381-
// Overwrite protocol back to HTTP, export to url "my_custom_endpoint"
389+
// Overwrite protocol back to HTTP, export to url "http://my_custom_endpoint"
382390
process.env.OTEL_EXPORTER_OTLP_METRICS_PROTOCOL = 'http/protobuf';
383391
exporter = ApplicationSignalsExporterProvider.Instance.createExporter();
384392
expect(exporter).toBeInstanceOf(OTLPHttpOTLPMetricExporter);
385-
expect('my_custom_endpoint').toEqual((exporter as any)._otlpExporter.url);
393+
expect('http://my_custom_endpoint').toEqual((exporter as any)._delegate._transport._transport._parameters.url);
386394

387395
// Cleanup
388396
delete process.env.OTEL_EXPORTER_OTLP_METRICS_PROTOCOL;

0 commit comments

Comments
 (0)