Skip to content

Commit 7dabd39

Browse files
authored
Enable suppressInternalInstrumentation for AWS-SDK and Mongoose Instrumentations (#70)
*Issue #, if available:* *Description of changes:* 1. Enable `suppressInternalInstrumentation` for AWS-SDK and Mongoose Instrumentations 2. Remove workaround that suppresses metrics from child spans of AWS SDK spans *Testing:* - Tested on ECS Fargate and Local machine - AWS SDK has no http child span - Mongoose has no mongodb child span By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
1 parent 5e967ac commit 7dabd39

File tree

3 files changed

+24
-33
lines changed

3 files changed

+24
-33
lines changed

aws-distro-opentelemetry-node-autoinstrumentation/src/aws-span-processing-util.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ import {
1717
SEMATTRS_RPC_SYSTEM,
1818
} from '@opentelemetry/semantic-conventions';
1919
import { AWS_ATTRIBUTE_KEYS } from './aws-attribute-keys';
20-
import * as SQL_DIALECT_KEYWORDS_JSON from './configuration/sql_dialect_keywords.json';
2120
import { AWS_LAMBDA_FUNCTION_NAME_CONFIG, isLambdaEnvironment } from './aws-opentelemetry-configurator';
21+
import * as SQL_DIALECT_KEYWORDS_JSON from './configuration/sql_dialect_keywords.json';
2222

2323
/** Utility class designed to support shared logic across AWS Span Processors. */
2424
export class AwsSpanProcessingUtil {
@@ -124,23 +124,6 @@ export class AwsSpanProcessingUtil {
124124
}
125125

126126
static shouldGenerateDependencyMetricAttributes(span: ReadableSpan): boolean {
127-
// Divergence from Java/Python
128-
// In OTel JS, the AWS SDK instrumentation creates two Client Spans, one for AWS SDK,
129-
// and another for the underlying HTTP Client used by the SDK. The following code block
130-
// ensures that dependency metrics are not generated for direct descendent of AWS SDK Spans.
131-
const isAwsSdkDescendent: AttributeValue | undefined = span.attributes[AWS_ATTRIBUTE_KEYS.AWS_SDK_DESCENDANT];
132-
if (isAwsSdkDescendent !== undefined && isAwsSdkDescendent === 'true') {
133-
return false;
134-
}
135-
136-
// TODO:
137-
// Telemetry improvements:
138-
// - return false for dns instrumentation client spans
139-
// (suppress metrics for spans with name: `dns.lookup`)
140-
// - return false for mongoose instrumentation client spans in
141-
// favor of lower level mongodb instrumentation client spans
142-
// (suppress metrics for spans attribute 'db.system': 'mongoose')
143-
144127
return (
145128
SpanKind.CLIENT === span.kind ||
146129
SpanKind.PRODUCER === span.kind ||

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
import { Instrumentation } from '@opentelemetry/instrumentation';
5-
import { AwsSdkInstrumentationConfig, NormalizedRequest } from '@opentelemetry/instrumentation-aws-sdk';
6-
import { AWS_ATTRIBUTE_KEYS } from '../aws-attribute-keys';
7-
import { RequestMetadata } from '../third-party/otel/aws/services/ServiceExtension';
8-
import { KinesisServiceExtension } from './aws/services/kinesis';
9-
import { S3ServiceExtension } from './aws/services/s3';
10-
import { AwsLambdaInstrumentation } from '@opentelemetry/instrumentation-aws-lambda';
114
import {
5+
diag,
6+
isSpanContextValid,
127
Context as OtelContext,
138
context as otelContext,
14-
trace,
159
propagation,
16-
TextMapGetter,
17-
isSpanContextValid,
1810
ROOT_CONTEXT,
19-
diag,
11+
TextMapGetter,
12+
trace,
2013
} from '@opentelemetry/api';
21-
import { APIGatewayProxyEventHeaders, Context } from 'aws-lambda';
14+
import { Instrumentation } from '@opentelemetry/instrumentation';
15+
import { AwsLambdaInstrumentation } from '@opentelemetry/instrumentation-aws-lambda';
16+
import { AwsSdkInstrumentationConfig, NormalizedRequest } from '@opentelemetry/instrumentation-aws-sdk';
2217
import { AWSXRAY_TRACE_ID_HEADER, AWSXRayPropagator } from '@opentelemetry/propagator-aws-xray';
18+
import { APIGatewayProxyEventHeaders, Context } from 'aws-lambda';
19+
import { AWS_ATTRIBUTE_KEYS } from '../aws-attribute-keys';
20+
import { RequestMetadata } from '../third-party/otel/aws/services/ServiceExtension';
21+
import { KinesisServiceExtension } from './aws/services/kinesis';
22+
import { S3ServiceExtension } from './aws/services/s3';
2323

2424
export const traceContextEnvironmentKey = '_X_AMZN_TRACE_ID';
2525
const awsPropagator = new AWSXRayPropagator();

aws-distro-opentelemetry-node-autoinstrumentation/src/register.ts

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

5-
import { DiagConsoleLogger, diag } from '@opentelemetry/api';
6-
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
5+
import { diag, DiagConsoleLogger } from '@opentelemetry/api';
6+
import { getNodeAutoInstrumentations, InstrumentationConfigMap } from '@opentelemetry/auto-instrumentations-node';
77
import { Instrumentation } from '@opentelemetry/instrumentation';
88
import * as opentelemetry from '@opentelemetry/sdk-node';
99
import { AwsOpentelemetryConfigurator } from './aws-opentelemetry-configurator';
@@ -43,7 +43,15 @@ export function setAwsDefaultEnvironmentVariables(): void {
4343
}
4444
setAwsDefaultEnvironmentVariables();
4545

46-
const instrumentations: Instrumentation[] = getNodeAutoInstrumentations();
46+
const instrumentationConfigs: InstrumentationConfigMap = {
47+
'@opentelemetry/instrumentation-aws-sdk': {
48+
suppressInternalInstrumentation: true,
49+
},
50+
'@opentelemetry/instrumentation-mongoose': {
51+
suppressInternalInstrumentation: true,
52+
},
53+
};
54+
const instrumentations: Instrumentation[] = getNodeAutoInstrumentations(instrumentationConfigs);
4755

4856
// Apply instrumentation patches
4957
applyInstrumentationPatches(instrumentations);

0 commit comments

Comments
 (0)