@opentelemetry/instrumentation-aws-sdk 0.36.2 → 0.37.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -20,11 +20,11 @@ npm install --save @opentelemetry/instrumentation-aws-sdk
20
20
  For further automatic instrumentation instruction see the [@opentelemetry/instrumentation](https://www.npmjs.com/package/@opentelemetry/instrumentation) package.
21
21
 
22
22
  ```js
23
- const { NodeTracerProvider } = require("@opentelemetry/sdk-trace-node");
24
- const { registerInstrumentations } = require("@opentelemetry/instrumentation");
23
+ const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
24
+ const { registerInstrumentations } = require('@opentelemetry/instrumentation');
25
25
  const {
26
26
  AwsInstrumentation,
27
- } = require("@opentelemetry/instrumentation-aws-sdk");
27
+ } = require('@opentelemetry/instrumentation-aws-sdk');
28
28
 
29
29
  const provider = new NodeTracerProvider();
30
30
  provider.register();
@@ -42,13 +42,14 @@ registerInstrumentations({
42
42
 
43
43
  aws-sdk instrumentation has few options available to choose from. You can set the following:
44
44
 
45
- | Options | Type | Description |
46
- | --------------------------------- | ----------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
47
- | `preRequestHook` | `AwsSdkRequestCustomAttributeFunction` | Hook called before request send, which allow to add custom attributes to span. |
48
- | `responseHook` | `AwsSdkResponseCustomAttributeFunction` | Hook for adding custom attributes when response is received from aws. |
49
- | `sqsProcessHook` | `AwsSdkSqsProcessCustomAttributeFunction` | Hook called after starting sqs `process` span (for each sqs received message), which allow to add custom attributes to it. |
50
- | `suppressInternalInstrumentation` | `boolean` | Most aws operation use http requests under the hood. Set this to `true` to hide all underlying http spans. |
51
- | `sqsExtractContextPropagationFromPayload` | `boolean` | Will parse and extract context propagation headers from SQS Payload, false by default. [When should it be used?](./doc/sns.md#integration-with-sqs)|
45
+ | Options | Type | Description |
46
+ | ----------------------------------------- | ----------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
47
+ | `preRequestHook` | `AwsSdkRequestCustomAttributeFunction` | Hook called before request send, which allow to add custom attributes to span. |
48
+ | `responseHook` | `AwsSdkResponseCustomAttributeFunction` | Hook for adding custom attributes when response is received from aws. |
49
+ | `sqsProcessHook` | `AwsSdkSqsProcessCustomAttributeFunction` | Hook called after starting sqs `process` span (for each sqs received message), which allow to add custom attributes to it. |
50
+ | `suppressInternalInstrumentation` | `boolean` | Most aws operation use http requests under the hood. Set this to `true` to hide all underlying http spans. |
51
+ | `sqsExtractContextPropagationFromPayload` | `boolean` | Will parse and extract context propagation headers from SQS Payload, false by default. [When should it be used?](./doc/sns.md#integration-with-sqs) |
52
+ | `dynamoDBStatementSerializer` | `AwsSdkDynamoDBStatementSerializer` | AWS SDK instrumentation will serialize DynamoDB commands to the `db.statement` attribute using the specified function. Defaults to using a serializer that returns `undefined`. |
52
53
 
53
54
  ## Span Attributes
54
55
 
@@ -82,8 +83,8 @@ Usage example:
82
83
  ```js
83
84
  awsInstrumentationConfig = {
84
85
  preRequestHook: (span, request) => {
85
- if (span.serviceName === "s3") {
86
- span.setAttribute("s3.bucket.name", request.commandInput["Bucket"]);
86
+ if (span.serviceName === 's3') {
87
+ span.setAttribute('s3.bucket.name', request.commandInput['Bucket']);
87
88
  }
88
89
  },
89
90
  };
@@ -216,7 +216,7 @@ class AwsInstrumentation extends instrumentation_1.InstrumentationBase {
216
216
  const serviceName = (_b = clientConfig === null || clientConfig === void 0 ? void 0 : clientConfig.serviceId) !== null && _b !== void 0 ? _b : (0, utils_1.removeSuffixFromStringIfExists)(awsExecutionContext.clientName, 'Client');
217
217
  const commandName = (_c = awsExecutionContext.commandName) !== null && _c !== void 0 ? _c : (_d = command.constructor) === null || _d === void 0 ? void 0 : _d.name;
218
218
  const normalizedRequest = (0, utils_1.normalizeV3Request)(serviceName, commandName, command.input, undefined);
219
- const requestMetadata = self.servicesExtensions.requestPreSpanHook(normalizedRequest);
219
+ const requestMetadata = self.servicesExtensions.requestPreSpanHook(normalizedRequest, self._config, self._diag);
220
220
  const span = self._startAwsV3Span(normalizedRequest, requestMetadata);
221
221
  const activeContextWithSpan = api_1.trace.setSpan(api_1.context.active(), span);
222
222
  const handlerPromise = new Promise((resolve, reject) => {
@@ -304,7 +304,7 @@ class AwsInstrumentation extends instrumentation_1.InstrumentationBase {
304
304
  return original.call(this, callback);
305
305
  }
306
306
  const normalizedRequest = (0, utils_1.normalizeV2Request)(this);
307
- const requestMetadata = self.servicesExtensions.requestPreSpanHook(normalizedRequest);
307
+ const requestMetadata = self.servicesExtensions.requestPreSpanHook(normalizedRequest, self._config, self._diag);
308
308
  const span = self._startAwsV2Span(this, requestMetadata, normalizedRequest);
309
309
  this[REQUEST_SPAN_KEY] = span;
310
310
  const activeContextWithSpan = api_1.trace.setSpan(api_1.context.active(), span);
@@ -325,7 +325,7 @@ class AwsInstrumentation extends instrumentation_1.InstrumentationBase {
325
325
  return original.apply(this, args);
326
326
  }
327
327
  const normalizedRequest = (0, utils_1.normalizeV2Request)(this);
328
- const requestMetadata = self.servicesExtensions.requestPreSpanHook(normalizedRequest);
328
+ const requestMetadata = self.servicesExtensions.requestPreSpanHook(normalizedRequest, self._config, self._diag);
329
329
  const span = self._startAwsV2Span(this, requestMetadata, normalizedRequest);
330
330
  this[REQUEST_SPAN_KEY] = span;
331
331
  const activeContextWithSpan = api_1.trace.setSpan(api_1.context.active(), span);
@@ -1 +1 @@
1
- {"version":3,"file":"aws-sdk.js","sourceRoot":"","sources":["../../src/aws-sdk.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,4CAQ4B;AAC5B,8CAAsD;AAEtD,mCAAyC;AACzC,yCAAgD;AAQhD,uCAAoC;AACpC,oEAOwC;AAQxC,mCAMiB;AAEjB,8EAAyE;AAEzE,MAAM,oBAAoB,GAAG,MAAM,CACjC,qDAAqD,CACtD,CAAC;AAKF,MAAM,gBAAgB,GAAG,MAAM,CAAC,4CAA4C,CAAC,CAAC;AAK9E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ourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n Span,\n SpanKind,\n context,\n trace,\n Context,\n diag,\n SpanStatusCode,\n} from '@opentelemetry/api';\nimport { suppressTracing } from '@opentelemetry/core';\nimport type * as AWS from 'aws-sdk';\nimport { AttributeNames } from './enums';\nimport { ServicesExtensions } from './services';\nimport {\n AwsSdkInstrumentationConfig,\n AwsSdkRequestHookInformation,\n AwsSdkResponseHookInformation,\n NormalizedRequest,\n NormalizedResponse,\n} from './types';\nimport { VERSION } from './version';\nimport {\n InstrumentationBase,\n InstrumentationModuleDefinition,\n InstrumentationNodeModuleDefinition,\n InstrumentationNodeModuleFile,\n isWrapped,\n safeExecuteInTheMiddle,\n} from '@opentelemetry/instrumentation';\nimport type {\n MiddlewareStack,\n HandlerExecutionContext,\n Command as AwsV3Command,\n Handler as AwsV3MiddlewareHandler,\n InitializeHandlerArguments,\n} from '@aws-sdk/types';\nimport {\n bindPromise,\n extractAttributesFromNormalizedRequest,\n normalizeV2Request,\n normalizeV3Request,\n removeSuffixFromStringIfExists,\n} from './utils';\nimport { RequestMetadata } from './services/ServiceExtension';\nimport { SemanticAttributes } from '@opentelemetry/semantic-conventions';\n\nconst V3_CLIENT_CONFIG_KEY = Symbol(\n 'opentelemetry.instrumentation.aws-sdk.client.config'\n);\ntype V3PluginCommand = AwsV3Command<any, any, any, any, any> & {\n [V3_CLIENT_CONFIG_KEY]?: any;\n};\n\nconst REQUEST_SPAN_KEY = Symbol('opentelemetry.instrumentation.aws-sdk.span');\ntype V2PluginRequest = AWS.Request<any, any> & {\n [REQUEST_SPAN_KEY]?: Span;\n};\n\nexport class AwsInstrumentation extends InstrumentationBase<any> {\n static readonly component = 'aws-sdk';\n protected override _config!: AwsSdkInstrumentationConfig;\n private servicesExtensions: ServicesExtensions = new ServicesExtensions();\n\n constructor(config: AwsSdkInstrumentationConfig = {}) {\n super(\n '@opentelemetry/instrumentation-aws-sdk',\n VERSION,\n Object.assign({}, config)\n );\n }\n\n override setConfig(config: AwsSdkInstrumentationConfig = {}) {\n this._config = Object.assign({}, config);\n }\n\n protected init(): InstrumentationModuleDefinition<any>[] {\n const v3MiddlewareStackFileOldVersions = new InstrumentationNodeModuleFile(\n '@aws-sdk/middleware-stack/dist/cjs/MiddlewareStack.js',\n ['>=3.1.0 <3.35.0'],\n this.patchV3ConstructStack.bind(this),\n this.unpatchV3ConstructStack.bind(this)\n );\n const v3MiddlewareStackFileNewVersions = new InstrumentationNodeModuleFile(\n '@aws-sdk/middleware-stack/dist-cjs/MiddlewareStack.js',\n ['>=3.35.0'],\n this.patchV3ConstructStack.bind(this),\n this.unpatchV3ConstructStack.bind(this)\n );\n\n // as for aws-sdk v3.13.1, constructStack is exported from @aws-sdk/middleware-stack as\n // getter instead of function, which fails shimmer.\n // so we are patching the MiddlewareStack.js file directly to get around it.\n const v3MiddlewareStack = new InstrumentationNodeModuleDefinition<\n typeof AWS\n >('@aws-sdk/middleware-stack', ['^3.1.0'], undefined, undefined, [\n v3MiddlewareStackFileOldVersions,\n v3MiddlewareStackFileNewVersions,\n ]);\n\n // patch for @smithy/middleware-stack for aws-sdk packages v3.363.0+\n const v3SmithyMiddlewareStackFile = new InstrumentationNodeModuleFile(\n '@smithy/middleware-stack/dist-cjs/MiddlewareStack.js',\n ['>=1.0.1'],\n this.patchV3ConstructStack.bind(this),\n this.unpatchV3ConstructStack.bind(this)\n );\n const v3SmithyMiddlewareStack = new InstrumentationNodeModuleDefinition(\n '@smithy/middleware-stack',\n ['>=2.0.0'],\n undefined,\n undefined,\n [v3SmithyMiddlewareStackFile]\n );\n\n const v3SmithyClient = new InstrumentationNodeModuleDefinition<typeof AWS>(\n '@aws-sdk/smithy-client',\n ['^3.1.0'],\n this.patchV3SmithyClient.bind(this),\n this.unpatchV3SmithyClient.bind(this)\n );\n\n // patch for new @smithy/smithy-client for aws-sdk packages v3.363.0+\n const v3NewSmithyClient = new InstrumentationNodeModuleDefinition(\n '@smithy/smithy-client',\n ['>=1.0.3'],\n this.patchV3SmithyClient.bind(this),\n this.unpatchV3SmithyClient.bind(this)\n );\n\n const v2Request = new InstrumentationNodeModuleFile<typeof AWS>(\n 'aws-sdk/lib/core.js',\n ['^2.308.0'],\n this.patchV2.bind(this),\n this.unpatchV2.bind(this)\n );\n\n const v2Module = new InstrumentationNodeModuleDefinition<typeof AWS>(\n 'aws-sdk',\n ['^2.308.0'],\n undefined,\n undefined,\n [v2Request]\n );\n\n return [\n v2Module,\n v3MiddlewareStack,\n v3SmithyMiddlewareStack,\n v3SmithyClient,\n v3NewSmithyClient,\n ];\n }\n\n protected patchV3ConstructStack(moduleExports: any, moduleVersion?: string) {\n diag.debug(\n 'aws-sdk instrumentation: applying patch to aws-sdk v3 constructStack'\n );\n this._wrap(\n moduleExports,\n 'constructStack',\n this._getV3ConstructStackPatch.bind(this, moduleVersion)\n );\n return moduleExports;\n }\n\n protected unpatchV3ConstructStack(moduleExports: any) {\n diag.debug(\n 'aws-sdk instrumentation: applying unpatch to aws-sdk v3 constructStack'\n );\n this._unwrap(moduleExports, 'constructStack');\n return moduleExports;\n }\n\n protected patchV3SmithyClient(moduleExports: any) {\n diag.debug(\n 'aws-sdk instrumentation: applying patch to aws-sdk v3 client send'\n );\n this._wrap(\n moduleExports.Client.prototype,\n 'send',\n this._getV3SmithyClientSendPatch.bind(this)\n );\n return moduleExports;\n }\n\n protected unpatchV3SmithyClient(moduleExports: any) {\n diag.debug(\n 'aws-sdk instrumentation: applying patch to aws-sdk v3 constructStack'\n );\n this._unwrap(moduleExports.Client.prototype, 'send');\n return moduleExports;\n }\n\n protected patchV2(moduleExports: any, moduleVersion?: string) {\n diag.debug(\n `aws-sdk instrumentation: applying patch to ${AwsInstrumentation.component}`\n );\n this.unpatchV2(moduleExports);\n this._wrap(\n moduleExports?.Request.prototype,\n 'send',\n this._getRequestSendPatch.bind(this, moduleVersion)\n );\n this._wrap(\n moduleExports?.Request.prototype,\n 'promise',\n this._getRequestPromisePatch.bind(this, moduleVersion)\n );\n\n return moduleExports;\n }\n\n protected unpatchV2(moduleExports?: any) {\n if (isWrapped(moduleExports?.Request.prototype.send)) {\n this._unwrap(moduleExports!.Request.prototype, 'send');\n }\n if (isWrapped(moduleExports?.Request.prototype.promise)) {\n this._unwrap(moduleExports!.Request.prototype, 'promise');\n }\n }\n\n private _startAwsV3Span(\n normalizedRequest: NormalizedRequest,\n metadata: RequestMetadata\n ): Span {\n const name =\n metadata.spanName ??\n `${normalizedRequest.serviceName}.${normalizedRequest.commandName}`;\n const newSpan = this.tracer.startSpan(name, {\n kind: metadata.spanKind ?? SpanKind.CLIENT,\n attributes: {\n ...extractAttributesFromNormalizedRequest(normalizedRequest),\n ...metadata.spanAttributes,\n },\n });\n\n return newSpan;\n }\n\n private _startAwsV2Span(\n request: AWS.Request<any, any>,\n metadata: RequestMetadata,\n normalizedRequest: NormalizedRequest\n ): Span {\n const operation = (request as any).operation;\n const service = (request as any).service;\n const serviceIdentifier = service?.serviceIdentifier;\n const name =\n metadata.spanName ??\n `${normalizedRequest.serviceName}.${normalizedRequest.commandName}`;\n\n const newSpan = this.tracer.startSpan(name, {\n kind: metadata.spanKind ?? SpanKind.CLIENT,\n attributes: {\n [AttributeNames.AWS_OPERATION]: operation,\n [AttributeNames.AWS_SIGNATURE_VERSION]:\n service?.config?.signatureVersion,\n [AttributeNames.AWS_SERVICE_API]: service?.api?.className,\n [AttributeNames.AWS_SERVICE_IDENTIFIER]: serviceIdentifier,\n [AttributeNames.AWS_SERVICE_NAME]: service?.api?.abbreviation,\n ...extractAttributesFromNormalizedRequest(normalizedRequest),\n ...metadata.spanAttributes,\n },\n });\n\n return newSpan;\n }\n\n private _callUserPreRequestHook(\n span: Span,\n request: NormalizedRequest,\n moduleVersion: string | undefined\n ) {\n if (this._config?.preRequestHook) {\n const requestInfo: AwsSdkRequestHookInformation = {\n moduleVersion,\n request,\n };\n safeExecuteInTheMiddle(\n () => this._config.preRequestHook!(span, requestInfo),\n (e: Error | undefined) => {\n if (e)\n diag.error(\n `${AwsInstrumentation.component} instrumentation: preRequestHook error`,\n e\n );\n },\n true\n );\n }\n }\n\n private _callUserResponseHook(span: Span, response: NormalizedResponse) {\n const responseHook = this._config?.responseHook;\n if (!responseHook) return;\n\n const responseInfo: AwsSdkResponseHookInformation = {\n response,\n };\n safeExecuteInTheMiddle(\n () => responseHook(span, responseInfo),\n (e: Error | undefined) => {\n if (e)\n diag.error(\n `${AwsInstrumentation.component} instrumentation: responseHook error`,\n e\n );\n },\n true\n );\n }\n\n private _registerV2CompletedEvent(\n span: Span,\n v2Request: V2PluginRequest,\n normalizedRequest: NormalizedRequest,\n completedEventContext: Context\n ) {\n const self = this;\n v2Request.on('complete', response => {\n // read issue https://github.com/aspecto-io/opentelemetry-ext-js/issues/60\n context.with(completedEventContext, () => {\n if (!v2Request[REQUEST_SPAN_KEY]) {\n return;\n }\n delete v2Request[REQUEST_SPAN_KEY];\n\n const requestId = response.requestId;\n const normalizedResponse: NormalizedResponse = {\n data: response.data,\n request: normalizedRequest,\n requestId: requestId,\n };\n\n self._callUserResponseHook(span, normalizedResponse);\n if (response.error) {\n span.recordException(response.error);\n } else {\n this.servicesExtensions.responseHook(\n normalizedResponse,\n span,\n self.tracer,\n self._config\n );\n }\n\n span.setAttribute(AttributeNames.AWS_REQUEST_ID, requestId);\n\n const httpStatusCode = response.httpResponse?.statusCode;\n if (httpStatusCode) {\n span.setAttribute(\n SemanticAttributes.HTTP_STATUS_CODE,\n httpStatusCode\n );\n }\n span.end();\n });\n });\n }\n\n private _getV3ConstructStackPatch(\n moduleVersion: string | undefined,\n original: (...args: unknown[]) => MiddlewareStack<any, any>\n ) {\n const self = this;\n return function constructStack(\n this: any,\n ...args: unknown[]\n ): MiddlewareStack<any, any> {\n const stack: MiddlewareStack<any, any> = original.apply(this, args);\n self.patchV3MiddlewareStack(moduleVersion, stack);\n return stack;\n };\n }\n\n private _getV3SmithyClientSendPatch(\n original: (...args: unknown[]) => Promise<any>\n ) {\n return function send(\n this: any,\n command: V3PluginCommand,\n ...args: unknown[]\n ): Promise<any> {\n command[V3_CLIENT_CONFIG_KEY] = this.config;\n return original.apply(this, [command, ...args]);\n };\n }\n\n private patchV3MiddlewareStack(\n moduleVersion: string | undefined,\n middlewareStackToPatch: MiddlewareStack<any, any>\n ) {\n if (!isWrapped(middlewareStackToPatch.resolve)) {\n this._wrap(\n middlewareStackToPatch,\n 'resolve',\n this._getV3MiddlewareStackResolvePatch.bind(this, moduleVersion)\n );\n }\n\n // 'clone' and 'concat' functions are internally calling 'constructStack' which is in same\n // module, thus not patched, and we need to take care of it specifically.\n this._wrap(\n middlewareStackToPatch,\n 'clone',\n this._getV3MiddlewareStackClonePatch.bind(this, moduleVersion)\n );\n this._wrap(\n middlewareStackToPatch,\n 'concat',\n this._getV3MiddlewareStackClonePatch.bind(this, moduleVersion)\n );\n }\n\n private _getV3MiddlewareStackClonePatch(\n moduleVersion: string | undefined,\n original: (...args: any[]) => MiddlewareStack<any, any>\n ) {\n const self = this;\n return function (this: any, ...args: any[]) {\n const newStack = original.apply(this, args);\n self.patchV3MiddlewareStack(moduleVersion, newStack);\n return newStack;\n };\n }\n\n private _getV3MiddlewareStackResolvePatch(\n moduleVersion: string | undefined,\n original: (\n _handler: any,\n context: HandlerExecutionContext\n ) => AwsV3MiddlewareHandler<any, any>\n ) {\n const self = this;\n return function (\n this: any,\n _handler: any,\n awsExecutionContext: HandlerExecutionContext\n ): AwsV3MiddlewareHandler<any, any> {\n const origHandler = original.call(this, _handler, awsExecutionContext);\n const patchedHandler = function (\n this: any,\n command: InitializeHandlerArguments<any> & {\n [V3_CLIENT_CONFIG_KEY]?: any;\n }\n ): Promise<any> {\n const clientConfig = command[V3_CLIENT_CONFIG_KEY];\n const regionPromise = clientConfig?.region?.();\n const serviceName =\n clientConfig?.serviceId ??\n removeSuffixFromStringIfExists(\n awsExecutionContext.clientName,\n 'Client'\n );\n const commandName =\n awsExecutionContext.commandName ?? command.constructor?.name;\n const normalizedRequest = normalizeV3Request(\n serviceName,\n commandName,\n command.input,\n undefined\n );\n const requestMetadata =\n self.servicesExtensions.requestPreSpanHook(normalizedRequest);\n const span = self._startAwsV3Span(normalizedRequest, requestMetadata);\n const activeContextWithSpan = trace.setSpan(context.active(), span);\n\n const handlerPromise = new Promise((resolve, reject) => {\n Promise.resolve(regionPromise)\n .then(resolvedRegion => {\n normalizedRequest.region = resolvedRegion;\n span.setAttribute(AttributeNames.AWS_REGION, resolvedRegion);\n })\n .catch(e => {\n // there is nothing much we can do in this case.\n // we'll just continue without region\n diag.debug(\n `${AwsInstrumentation.component} instrumentation: failed to extract region from async function`,\n e\n );\n })\n .finally(() => {\n self._callUserPreRequestHook(\n span,\n normalizedRequest,\n moduleVersion\n );\n const resultPromise = context.with(activeContextWithSpan, () => {\n self.servicesExtensions.requestPostSpanHook(normalizedRequest);\n return self._callOriginalFunction(() =>\n origHandler.call(this, command)\n );\n });\n const promiseWithResponseLogic = resultPromise\n .then(response => {\n const requestId = response.output?.$metadata?.requestId;\n if (requestId) {\n span.setAttribute(AttributeNames.AWS_REQUEST_ID, requestId);\n }\n\n const httpStatusCode =\n response.output?.$metadata?.httpStatusCode;\n if (httpStatusCode) {\n span.setAttribute(\n SemanticAttributes.HTTP_STATUS_CODE,\n httpStatusCode\n );\n }\n\n const extendedRequestId =\n response.output?.$metadata?.extendedRequestId;\n if (extendedRequestId) {\n span.setAttribute(\n AttributeNames.AWS_REQUEST_EXTENDED_ID,\n extendedRequestId\n );\n }\n\n const normalizedResponse: NormalizedResponse = {\n data: response.output,\n request: normalizedRequest,\n requestId: requestId,\n };\n self.servicesExtensions.responseHook(\n normalizedResponse,\n span,\n self.tracer,\n self._config\n );\n self._callUserResponseHook(span, normalizedResponse);\n return response;\n })\n .catch(err => {\n const requestId = err?.RequestId;\n if (requestId) {\n span.setAttribute(AttributeNames.AWS_REQUEST_ID, requestId);\n }\n const extendedRequestId = err?.extendedRequestId;\n if (extendedRequestId) {\n span.setAttribute(\n AttributeNames.AWS_REQUEST_EXTENDED_ID,\n extendedRequestId\n );\n }\n\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: err.message,\n });\n span.recordException(err);\n throw err;\n })\n .finally(() => {\n span.end();\n });\n promiseWithResponseLogic\n .then(res => {\n resolve(res);\n })\n .catch(err => reject(err));\n });\n });\n\n return requestMetadata.isIncoming\n ? bindPromise(handlerPromise, activeContextWithSpan, 2)\n : handlerPromise;\n };\n return patchedHandler;\n };\n }\n\n private _getRequestSendPatch(\n moduleVersion: string | undefined,\n original: (callback?: (err: any, data: any) => void) => void\n ) {\n const self = this;\n return function (\n this: V2PluginRequest,\n callback?: (err: any, data: any) => void\n ) {\n /*\n if the span was already started, we don't want to start a new one\n when Request.promise() is called\n */\n if (this[REQUEST_SPAN_KEY]) {\n return original.call(this, callback);\n }\n\n const normalizedRequest = normalizeV2Request(this);\n const requestMetadata =\n self.servicesExtensions.requestPreSpanHook(normalizedRequest);\n const span = self._startAwsV2Span(\n this,\n requestMetadata,\n normalizedRequest\n );\n this[REQUEST_SPAN_KEY] = span;\n const activeContextWithSpan = trace.setSpan(context.active(), span);\n const callbackWithContext = context.bind(activeContextWithSpan, callback);\n\n self._callUserPreRequestHook(span, normalizedRequest, moduleVersion);\n self._registerV2CompletedEvent(\n span,\n this,\n normalizedRequest,\n activeContextWithSpan\n );\n\n return context.with(activeContextWithSpan, () => {\n self.servicesExtensions.requestPostSpanHook(normalizedRequest);\n return self._callOriginalFunction(() =>\n original.call(this, callbackWithContext)\n );\n });\n };\n }\n\n private _getRequestPromisePatch(\n moduleVersion: string | undefined,\n original: (...args: unknown[]) => Promise<any>\n ) {\n const self = this;\n return function (this: V2PluginRequest, ...args: unknown[]): Promise<any> {\n // if the span was already started, we don't want to start a new one when Request.promise() is called\n if (this[REQUEST_SPAN_KEY]) {\n return original.apply(this, args);\n }\n\n const normalizedRequest = normalizeV2Request(this);\n const requestMetadata =\n self.servicesExtensions.requestPreSpanHook(normalizedRequest);\n const span = self._startAwsV2Span(\n this,\n requestMetadata,\n normalizedRequest\n );\n this[REQUEST_SPAN_KEY] = span;\n\n const activeContextWithSpan = trace.setSpan(context.active(), span);\n self._callUserPreRequestHook(span, normalizedRequest, moduleVersion);\n self._registerV2CompletedEvent(\n span,\n this,\n normalizedRequest,\n activeContextWithSpan\n );\n\n const origPromise: Promise<any> = context.with(\n activeContextWithSpan,\n () => {\n self.servicesExtensions.requestPostSpanHook(normalizedRequest);\n return self._callOriginalFunction(() =>\n original.call(this, arguments)\n );\n }\n );\n\n return requestMetadata.isIncoming\n ? bindPromise(origPromise, activeContextWithSpan)\n : origPromise;\n };\n }\n\n private _callOriginalFunction<T>(originalFunction: (...args: any[]) => T): T {\n if (this._config?.suppressInternalInstrumentation) {\n return context.with(suppressTracing(context.active()), originalFunction);\n } else {\n return originalFunction();\n }\n }\n}\n"]}
1
+ {"version":3,"file":"aws-sdk.js","sourceRoot":"","sources":["../../src/aws-sdk.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,4CAQ4B;AAC5B,8CAAsD;AAEtD,mCAAyC;AACzC,yCAAgD;AAQhD,uCAAoC;AACpC,oEAOwC;AAQxC,mCAMiB;AAEjB,8EAAyE;AAEzE,MAAM,oBAAoB,GAAG,MAAM,CACjC,qDAAqD,CACtD,CAAC;AAKF,MAAM,gBAAgB,GAAG,MAAM,CAAC,4CAA4C,CAAC,CAAC;AAK9E,MAAa,kBAAmB,SAAQ,qCAAwB;IAK9D,YAAY,SAAsC,EAAE;QAClD,KAAK,CACH,wCAAwC,EACxC,iBAAO,EACP,MAAM,CAAC,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BAAS,GAAG,SAAS,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n Span,\n SpanKind,\n context,\n trace,\n Context,\n diag,\n SpanStatusCode,\n} from '@opentelemetry/api';\nimport { suppressTracing } from '@opentelemetry/core';\nimport type * as AWS from 'aws-sdk';\nimport { AttributeNames } from './enums';\nimport { ServicesExtensions } from './services';\nimport {\n AwsSdkInstrumentationConfig,\n AwsSdkRequestHookInformation,\n AwsSdkResponseHookInformation,\n NormalizedRequest,\n NormalizedResponse,\n} from './types';\nimport { VERSION } from './version';\nimport {\n InstrumentationBase,\n InstrumentationModuleDefinition,\n InstrumentationNodeModuleDefinition,\n InstrumentationNodeModuleFile,\n isWrapped,\n safeExecuteInTheMiddle,\n} from '@opentelemetry/instrumentation';\nimport type {\n MiddlewareStack,\n HandlerExecutionContext,\n Command as AwsV3Command,\n Handler as AwsV3MiddlewareHandler,\n InitializeHandlerArguments,\n} from '@aws-sdk/types';\nimport {\n bindPromise,\n extractAttributesFromNormalizedRequest,\n normalizeV2Request,\n normalizeV3Request,\n removeSuffixFromStringIfExists,\n} from './utils';\nimport { RequestMetadata } from './services/ServiceExtension';\nimport { SemanticAttributes } from '@opentelemetry/semantic-conventions';\n\nconst V3_CLIENT_CONFIG_KEY = Symbol(\n 'opentelemetry.instrumentation.aws-sdk.client.config'\n);\ntype V3PluginCommand = AwsV3Command<any, any, any, any, any> & {\n [V3_CLIENT_CONFIG_KEY]?: any;\n};\n\nconst REQUEST_SPAN_KEY = Symbol('opentelemetry.instrumentation.aws-sdk.span');\ntype V2PluginRequest = AWS.Request<any, any> & {\n [REQUEST_SPAN_KEY]?: Span;\n};\n\nexport class AwsInstrumentation extends InstrumentationBase<any> {\n static readonly component = 'aws-sdk';\n protected override _config!: AwsSdkInstrumentationConfig;\n private servicesExtensions: ServicesExtensions = new ServicesExtensions();\n\n constructor(config: AwsSdkInstrumentationConfig = {}) {\n super(\n '@opentelemetry/instrumentation-aws-sdk',\n VERSION,\n Object.assign({}, config)\n );\n }\n\n override setConfig(config: AwsSdkInstrumentationConfig = {}) {\n this._config = Object.assign({}, config);\n }\n\n protected init(): InstrumentationModuleDefinition<any>[] {\n const v3MiddlewareStackFileOldVersions = new InstrumentationNodeModuleFile(\n '@aws-sdk/middleware-stack/dist/cjs/MiddlewareStack.js',\n ['>=3.1.0 <3.35.0'],\n this.patchV3ConstructStack.bind(this),\n this.unpatchV3ConstructStack.bind(this)\n );\n const v3MiddlewareStackFileNewVersions = new InstrumentationNodeModuleFile(\n '@aws-sdk/middleware-stack/dist-cjs/MiddlewareStack.js',\n ['>=3.35.0'],\n this.patchV3ConstructStack.bind(this),\n this.unpatchV3ConstructStack.bind(this)\n );\n\n // as for aws-sdk v3.13.1, constructStack is exported from @aws-sdk/middleware-stack as\n // getter instead of function, which fails shimmer.\n // so we are patching the MiddlewareStack.js file directly to get around it.\n const v3MiddlewareStack = new InstrumentationNodeModuleDefinition<\n typeof AWS\n >('@aws-sdk/middleware-stack', ['^3.1.0'], undefined, undefined, [\n v3MiddlewareStackFileOldVersions,\n v3MiddlewareStackFileNewVersions,\n ]);\n\n // patch for @smithy/middleware-stack for aws-sdk packages v3.363.0+\n const v3SmithyMiddlewareStackFile = new InstrumentationNodeModuleFile(\n '@smithy/middleware-stack/dist-cjs/MiddlewareStack.js',\n ['>=1.0.1'],\n this.patchV3ConstructStack.bind(this),\n this.unpatchV3ConstructStack.bind(this)\n );\n const v3SmithyMiddlewareStack = new InstrumentationNodeModuleDefinition(\n '@smithy/middleware-stack',\n ['>=2.0.0'],\n undefined,\n undefined,\n [v3SmithyMiddlewareStackFile]\n );\n\n const v3SmithyClient = new InstrumentationNodeModuleDefinition<typeof AWS>(\n '@aws-sdk/smithy-client',\n ['^3.1.0'],\n this.patchV3SmithyClient.bind(this),\n this.unpatchV3SmithyClient.bind(this)\n );\n\n // patch for new @smithy/smithy-client for aws-sdk packages v3.363.0+\n const v3NewSmithyClient = new InstrumentationNodeModuleDefinition(\n '@smithy/smithy-client',\n ['>=1.0.3'],\n this.patchV3SmithyClient.bind(this),\n this.unpatchV3SmithyClient.bind(this)\n );\n\n const v2Request = new InstrumentationNodeModuleFile<typeof AWS>(\n 'aws-sdk/lib/core.js',\n ['^2.308.0'],\n this.patchV2.bind(this),\n this.unpatchV2.bind(this)\n );\n\n const v2Module = new InstrumentationNodeModuleDefinition<typeof AWS>(\n 'aws-sdk',\n ['^2.308.0'],\n undefined,\n undefined,\n [v2Request]\n );\n\n return [\n v2Module,\n v3MiddlewareStack,\n v3SmithyMiddlewareStack,\n v3SmithyClient,\n v3NewSmithyClient,\n ];\n }\n\n protected patchV3ConstructStack(moduleExports: any, moduleVersion?: string) {\n diag.debug(\n 'aws-sdk instrumentation: applying patch to aws-sdk v3 constructStack'\n );\n this._wrap(\n moduleExports,\n 'constructStack',\n this._getV3ConstructStackPatch.bind(this, moduleVersion)\n );\n return moduleExports;\n }\n\n protected unpatchV3ConstructStack(moduleExports: any) {\n diag.debug(\n 'aws-sdk instrumentation: applying unpatch to aws-sdk v3 constructStack'\n );\n this._unwrap(moduleExports, 'constructStack');\n return moduleExports;\n }\n\n protected patchV3SmithyClient(moduleExports: any) {\n diag.debug(\n 'aws-sdk instrumentation: applying patch to aws-sdk v3 client send'\n );\n this._wrap(\n moduleExports.Client.prototype,\n 'send',\n this._getV3SmithyClientSendPatch.bind(this)\n );\n return moduleExports;\n }\n\n protected unpatchV3SmithyClient(moduleExports: any) {\n diag.debug(\n 'aws-sdk instrumentation: applying patch to aws-sdk v3 constructStack'\n );\n this._unwrap(moduleExports.Client.prototype, 'send');\n return moduleExports;\n }\n\n protected patchV2(moduleExports: any, moduleVersion?: string) {\n diag.debug(\n `aws-sdk instrumentation: applying patch to ${AwsInstrumentation.component}`\n );\n this.unpatchV2(moduleExports);\n this._wrap(\n moduleExports?.Request.prototype,\n 'send',\n this._getRequestSendPatch.bind(this, moduleVersion)\n );\n this._wrap(\n moduleExports?.Request.prototype,\n 'promise',\n this._getRequestPromisePatch.bind(this, moduleVersion)\n );\n\n return moduleExports;\n }\n\n protected unpatchV2(moduleExports?: any) {\n if (isWrapped(moduleExports?.Request.prototype.send)) {\n this._unwrap(moduleExports!.Request.prototype, 'send');\n }\n if (isWrapped(moduleExports?.Request.prototype.promise)) {\n this._unwrap(moduleExports!.Request.prototype, 'promise');\n }\n }\n\n private _startAwsV3Span(\n normalizedRequest: NormalizedRequest,\n metadata: RequestMetadata\n ): Span {\n const name =\n metadata.spanName ??\n `${normalizedRequest.serviceName}.${normalizedRequest.commandName}`;\n const newSpan = this.tracer.startSpan(name, {\n kind: metadata.spanKind ?? SpanKind.CLIENT,\n attributes: {\n ...extractAttributesFromNormalizedRequest(normalizedRequest),\n ...metadata.spanAttributes,\n },\n });\n\n return newSpan;\n }\n\n private _startAwsV2Span(\n request: AWS.Request<any, any>,\n metadata: RequestMetadata,\n normalizedRequest: NormalizedRequest\n ): Span {\n const operation = (request as any).operation;\n const service = (request as any).service;\n const serviceIdentifier = service?.serviceIdentifier;\n const name =\n metadata.spanName ??\n `${normalizedRequest.serviceName}.${normalizedRequest.commandName}`;\n\n const newSpan = this.tracer.startSpan(name, {\n kind: metadata.spanKind ?? SpanKind.CLIENT,\n attributes: {\n [AttributeNames.AWS_OPERATION]: operation,\n [AttributeNames.AWS_SIGNATURE_VERSION]:\n service?.config?.signatureVersion,\n [AttributeNames.AWS_SERVICE_API]: service?.api?.className,\n [AttributeNames.AWS_SERVICE_IDENTIFIER]: serviceIdentifier,\n [AttributeNames.AWS_SERVICE_NAME]: service?.api?.abbreviation,\n ...extractAttributesFromNormalizedRequest(normalizedRequest),\n ...metadata.spanAttributes,\n },\n });\n\n return newSpan;\n }\n\n private _callUserPreRequestHook(\n span: Span,\n request: NormalizedRequest,\n moduleVersion: string | undefined\n ) {\n if (this._config?.preRequestHook) {\n const requestInfo: AwsSdkRequestHookInformation = {\n moduleVersion,\n request,\n };\n safeExecuteInTheMiddle(\n () => this._config.preRequestHook!(span, requestInfo),\n (e: Error | undefined) => {\n if (e)\n diag.error(\n `${AwsInstrumentation.component} instrumentation: preRequestHook error`,\n e\n );\n },\n true\n );\n }\n }\n\n private _callUserResponseHook(span: Span, response: NormalizedResponse) {\n const responseHook = this._config?.responseHook;\n if (!responseHook) return;\n\n const responseInfo: AwsSdkResponseHookInformation = {\n response,\n };\n safeExecuteInTheMiddle(\n () => responseHook(span, responseInfo),\n (e: Error | undefined) => {\n if (e)\n diag.error(\n `${AwsInstrumentation.component} instrumentation: responseHook error`,\n e\n );\n },\n true\n );\n }\n\n private _registerV2CompletedEvent(\n span: Span,\n v2Request: V2PluginRequest,\n normalizedRequest: NormalizedRequest,\n completedEventContext: Context\n ) {\n const self = this;\n v2Request.on('complete', response => {\n // read issue https://github.com/aspecto-io/opentelemetry-ext-js/issues/60\n context.with(completedEventContext, () => {\n if (!v2Request[REQUEST_SPAN_KEY]) {\n return;\n }\n delete v2Request[REQUEST_SPAN_KEY];\n\n const requestId = response.requestId;\n const normalizedResponse: NormalizedResponse = {\n data: response.data,\n request: normalizedRequest,\n requestId: requestId,\n };\n\n self._callUserResponseHook(span, normalizedResponse);\n if (response.error) {\n span.recordException(response.error);\n } else {\n this.servicesExtensions.responseHook(\n normalizedResponse,\n span,\n self.tracer,\n self._config\n );\n }\n\n span.setAttribute(AttributeNames.AWS_REQUEST_ID, requestId);\n\n const httpStatusCode = response.httpResponse?.statusCode;\n if (httpStatusCode) {\n span.setAttribute(\n SemanticAttributes.HTTP_STATUS_CODE,\n httpStatusCode\n );\n }\n span.end();\n });\n });\n }\n\n private _getV3ConstructStackPatch(\n moduleVersion: string | undefined,\n original: (...args: unknown[]) => MiddlewareStack<any, any>\n ) {\n const self = this;\n return function constructStack(\n this: any,\n ...args: unknown[]\n ): MiddlewareStack<any, any> {\n const stack: MiddlewareStack<any, any> = original.apply(this, args);\n self.patchV3MiddlewareStack(moduleVersion, stack);\n return stack;\n };\n }\n\n private _getV3SmithyClientSendPatch(\n original: (...args: unknown[]) => Promise<any>\n ) {\n return function send(\n this: any,\n command: V3PluginCommand,\n ...args: unknown[]\n ): Promise<any> {\n command[V3_CLIENT_CONFIG_KEY] = this.config;\n return original.apply(this, [command, ...args]);\n };\n }\n\n private patchV3MiddlewareStack(\n moduleVersion: string | undefined,\n middlewareStackToPatch: MiddlewareStack<any, any>\n ) {\n if (!isWrapped(middlewareStackToPatch.resolve)) {\n this._wrap(\n middlewareStackToPatch,\n 'resolve',\n this._getV3MiddlewareStackResolvePatch.bind(this, moduleVersion)\n );\n }\n\n // 'clone' and 'concat' functions are internally calling 'constructStack' which is in same\n // module, thus not patched, and we need to take care of it specifically.\n this._wrap(\n middlewareStackToPatch,\n 'clone',\n this._getV3MiddlewareStackClonePatch.bind(this, moduleVersion)\n );\n this._wrap(\n middlewareStackToPatch,\n 'concat',\n this._getV3MiddlewareStackClonePatch.bind(this, moduleVersion)\n );\n }\n\n private _getV3MiddlewareStackClonePatch(\n moduleVersion: string | undefined,\n original: (...args: any[]) => MiddlewareStack<any, any>\n ) {\n const self = this;\n return function (this: any, ...args: any[]) {\n const newStack = original.apply(this, args);\n self.patchV3MiddlewareStack(moduleVersion, newStack);\n return newStack;\n };\n }\n\n private _getV3MiddlewareStackResolvePatch(\n moduleVersion: string | undefined,\n original: (\n _handler: any,\n context: HandlerExecutionContext\n ) => AwsV3MiddlewareHandler<any, any>\n ) {\n const self = this;\n return function (\n this: any,\n _handler: any,\n awsExecutionContext: HandlerExecutionContext\n ): AwsV3MiddlewareHandler<any, any> {\n const origHandler = original.call(this, _handler, awsExecutionContext);\n const patchedHandler = function (\n this: any,\n command: InitializeHandlerArguments<any> & {\n [V3_CLIENT_CONFIG_KEY]?: any;\n }\n ): Promise<any> {\n const clientConfig = command[V3_CLIENT_CONFIG_KEY];\n const regionPromise = clientConfig?.region?.();\n const serviceName =\n clientConfig?.serviceId ??\n removeSuffixFromStringIfExists(\n awsExecutionContext.clientName,\n 'Client'\n );\n const commandName =\n awsExecutionContext.commandName ?? command.constructor?.name;\n const normalizedRequest = normalizeV3Request(\n serviceName,\n commandName,\n command.input,\n undefined\n );\n const requestMetadata = self.servicesExtensions.requestPreSpanHook(\n normalizedRequest,\n self._config,\n self._diag\n );\n const span = self._startAwsV3Span(normalizedRequest, requestMetadata);\n const activeContextWithSpan = trace.setSpan(context.active(), span);\n\n const handlerPromise = new Promise((resolve, reject) => {\n Promise.resolve(regionPromise)\n .then(resolvedRegion => {\n normalizedRequest.region = resolvedRegion;\n span.setAttribute(AttributeNames.AWS_REGION, resolvedRegion);\n })\n .catch(e => {\n // there is nothing much we can do in this case.\n // we'll just continue without region\n diag.debug(\n `${AwsInstrumentation.component} instrumentation: failed to extract region from async function`,\n e\n );\n })\n .finally(() => {\n self._callUserPreRequestHook(\n span,\n normalizedRequest,\n moduleVersion\n );\n const resultPromise = context.with(activeContextWithSpan, () => {\n self.servicesExtensions.requestPostSpanHook(normalizedRequest);\n return self._callOriginalFunction(() =>\n origHandler.call(this, command)\n );\n });\n const promiseWithResponseLogic = resultPromise\n .then(response => {\n const requestId = response.output?.$metadata?.requestId;\n if (requestId) {\n span.setAttribute(AttributeNames.AWS_REQUEST_ID, requestId);\n }\n\n const httpStatusCode =\n response.output?.$metadata?.httpStatusCode;\n if (httpStatusCode) {\n span.setAttribute(\n SemanticAttributes.HTTP_STATUS_CODE,\n httpStatusCode\n );\n }\n\n const extendedRequestId =\n response.output?.$metadata?.extendedRequestId;\n if (extendedRequestId) {\n span.setAttribute(\n AttributeNames.AWS_REQUEST_EXTENDED_ID,\n extendedRequestId\n );\n }\n\n const normalizedResponse: NormalizedResponse = {\n data: response.output,\n request: normalizedRequest,\n requestId: requestId,\n };\n self.servicesExtensions.responseHook(\n normalizedResponse,\n span,\n self.tracer,\n self._config\n );\n self._callUserResponseHook(span, normalizedResponse);\n return response;\n })\n .catch(err => {\n const requestId = err?.RequestId;\n if (requestId) {\n span.setAttribute(AttributeNames.AWS_REQUEST_ID, requestId);\n }\n const extendedRequestId = err?.extendedRequestId;\n if (extendedRequestId) {\n span.setAttribute(\n AttributeNames.AWS_REQUEST_EXTENDED_ID,\n extendedRequestId\n );\n }\n\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: err.message,\n });\n span.recordException(err);\n throw err;\n })\n .finally(() => {\n span.end();\n });\n promiseWithResponseLogic\n .then(res => {\n resolve(res);\n })\n .catch(err => reject(err));\n });\n });\n\n return requestMetadata.isIncoming\n ? bindPromise(handlerPromise, activeContextWithSpan, 2)\n : handlerPromise;\n };\n return patchedHandler;\n };\n }\n\n private _getRequestSendPatch(\n moduleVersion: string | undefined,\n original: (callback?: (err: any, data: any) => void) => void\n ) {\n const self = this;\n return function (\n this: V2PluginRequest,\n callback?: (err: any, data: any) => void\n ) {\n /*\n if the span was already started, we don't want to start a new one\n when Request.promise() is called\n */\n if (this[REQUEST_SPAN_KEY]) {\n return original.call(this, callback);\n }\n\n const normalizedRequest = normalizeV2Request(this);\n const requestMetadata = self.servicesExtensions.requestPreSpanHook(\n normalizedRequest,\n self._config,\n self._diag\n );\n const span = self._startAwsV2Span(\n this,\n requestMetadata,\n normalizedRequest\n );\n this[REQUEST_SPAN_KEY] = span;\n const activeContextWithSpan = trace.setSpan(context.active(), span);\n const callbackWithContext = context.bind(activeContextWithSpan, callback);\n\n self._callUserPreRequestHook(span, normalizedRequest, moduleVersion);\n self._registerV2CompletedEvent(\n span,\n this,\n normalizedRequest,\n activeContextWithSpan\n );\n\n return context.with(activeContextWithSpan, () => {\n self.servicesExtensions.requestPostSpanHook(normalizedRequest);\n return self._callOriginalFunction(() =>\n original.call(this, callbackWithContext)\n );\n });\n };\n }\n\n private _getRequestPromisePatch(\n moduleVersion: string | undefined,\n original: (...args: unknown[]) => Promise<any>\n ) {\n const self = this;\n return function (this: V2PluginRequest, ...args: unknown[]): Promise<any> {\n // if the span was already started, we don't want to start a new one when Request.promise() is called\n if (this[REQUEST_SPAN_KEY]) {\n return original.apply(this, args);\n }\n\n const normalizedRequest = normalizeV2Request(this);\n const requestMetadata = self.servicesExtensions.requestPreSpanHook(\n normalizedRequest,\n self._config,\n self._diag\n );\n const span = self._startAwsV2Span(\n this,\n requestMetadata,\n normalizedRequest\n );\n this[REQUEST_SPAN_KEY] = span;\n\n const activeContextWithSpan = trace.setSpan(context.active(), span);\n self._callUserPreRequestHook(span, normalizedRequest, moduleVersion);\n self._registerV2CompletedEvent(\n span,\n this,\n normalizedRequest,\n activeContextWithSpan\n );\n\n const origPromise: Promise<any> = context.with(\n activeContextWithSpan,\n () => {\n self.servicesExtensions.requestPostSpanHook(normalizedRequest);\n return self._callOriginalFunction(() =>\n original.call(this, arguments)\n );\n }\n );\n\n return requestMetadata.isIncoming\n ? bindPromise(origPromise, activeContextWithSpan)\n : origPromise;\n };\n }\n\n private _callOriginalFunction<T>(originalFunction: (...args: any[]) => T): T {\n if (this._config?.suppressInternalInstrumentation) {\n return context.with(suppressTracing(context.active()), originalFunction);\n } else {\n return originalFunction();\n }\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { Span, SpanAttributes, SpanKind, Tracer } from '@opentelemetry/api';
1
+ import { DiagLogger, Span, SpanAttributes, SpanKind, Tracer } from '@opentelemetry/api';
2
2
  import { AwsSdkInstrumentationConfig, NormalizedRequest, NormalizedResponse } from '../types';
3
3
  export interface RequestMetadata {
4
4
  isIncoming: boolean;
@@ -7,7 +7,7 @@ export interface RequestMetadata {
7
7
  spanName?: string;
8
8
  }
9
9
  export interface ServiceExtension {
10
- requestPreSpanHook: (request: NormalizedRequest) => RequestMetadata;
10
+ requestPreSpanHook: (request: NormalizedRequest, config: AwsSdkInstrumentationConfig, diag: DiagLogger) => RequestMetadata;
11
11
  requestPostSpanHook?: (request: NormalizedRequest) => void;
12
12
  responseHook?: (response: NormalizedResponse, span: Span, tracer: Tracer, config: AwsSdkInstrumentationConfig) => void;
13
13
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ServiceExtension.js","sourceRoot":"","sources":["../../../src/services/ServiceExtension.ts"],"names":[],"mappings":"","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { Span, SpanAttributes, SpanKind, Tracer } from '@opentelemetry/api';\nimport {\n AwsSdkInstrumentationConfig,\n NormalizedRequest,\n NormalizedResponse,\n} from '../types';\n\nexport interface RequestMetadata {\n // isIncoming - if true, then the operation callback / promise should be bind with the operation's span\n isIncoming: boolean;\n spanAttributes?: SpanAttributes;\n spanKind?: SpanKind;\n spanName?: string;\n}\n\nexport interface ServiceExtension {\n // called before request is sent, and before span is started\n requestPreSpanHook: (request: NormalizedRequest) => RequestMetadata;\n\n // called before request is sent, and after span is started\n requestPostSpanHook?: (request: NormalizedRequest) => void;\n\n responseHook?: (\n response: NormalizedResponse,\n span: Span,\n tracer: Tracer,\n config: AwsSdkInstrumentationConfig\n ) => void;\n}\n"]}
1
+ {"version":3,"file":"ServiceExtension.js","sourceRoot":"","sources":["../../../src/services/ServiceExtension.ts"],"names":[],"mappings":"","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n DiagLogger,\n Span,\n SpanAttributes,\n SpanKind,\n Tracer,\n} from '@opentelemetry/api';\nimport {\n AwsSdkInstrumentationConfig,\n NormalizedRequest,\n NormalizedResponse,\n} from '../types';\n\nexport interface RequestMetadata {\n // isIncoming - if true, then the operation callback / promise should be bind with the operation's span\n isIncoming: boolean;\n spanAttributes?: SpanAttributes;\n spanKind?: SpanKind;\n spanName?: string;\n}\n\nexport interface ServiceExtension {\n // called before request is sent, and before span is started\n requestPreSpanHook: (\n request: NormalizedRequest,\n config: AwsSdkInstrumentationConfig,\n diag: DiagLogger\n ) => RequestMetadata;\n\n // called before request is sent, and after span is started\n requestPostSpanHook?: (request: NormalizedRequest) => void;\n\n responseHook?: (\n response: NormalizedResponse,\n span: Span,\n tracer: Tracer,\n config: AwsSdkInstrumentationConfig\n ) => void;\n}\n"]}
@@ -1,10 +1,10 @@
1
- import { Tracer, Span } from '@opentelemetry/api';
1
+ import { Tracer, Span, DiagLogger } from '@opentelemetry/api';
2
2
  import { ServiceExtension, RequestMetadata } from './ServiceExtension';
3
3
  import { AwsSdkInstrumentationConfig, NormalizedRequest, NormalizedResponse } from '../types';
4
4
  export declare class ServicesExtensions implements ServiceExtension {
5
5
  services: Map<string, ServiceExtension>;
6
6
  constructor();
7
- requestPreSpanHook(request: NormalizedRequest): RequestMetadata;
7
+ requestPreSpanHook(request: NormalizedRequest, config: AwsSdkInstrumentationConfig, diag: DiagLogger): RequestMetadata;
8
8
  requestPostSpanHook(request: NormalizedRequest): void;
9
9
  responseHook(response: NormalizedResponse, span: Span, tracer: Tracer, config: AwsSdkInstrumentationConfig): void;
10
10
  }
@@ -13,13 +13,13 @@ class ServicesExtensions {
13
13
  this.services.set('DynamoDB', new dynamodb_1.DynamodbServiceExtension());
14
14
  this.services.set('Lambda', new lambda_1.LambdaServiceExtension());
15
15
  }
16
- requestPreSpanHook(request) {
16
+ requestPreSpanHook(request, config, diag) {
17
17
  const serviceExtension = this.services.get(request.serviceName);
18
18
  if (!serviceExtension)
19
19
  return {
20
20
  isIncoming: false,
21
21
  };
22
- return serviceExtension.requestPreSpanHook(request);
22
+ return serviceExtension.requestPreSpanHook(request, config, diag);
23
23
  }
24
24
  requestPostSpanHook(request) {
25
25
  const serviceExtension = this.services.get(request.serviceName);
@@ -1 +1 @@
1
- {"version":3,"file":"ServicesExtensions.js","sourceRoot":"","sources":["../../../src/services/ServicesExtensions.ts"],"names":[],"mappings":";;;AAiBA,+BAA4C;AAM5C,yCAAsD;AACtD,+BAA4C;AAC5C,qCAAkD;AAElD,MAAa,kBAAkB;IAG7B;QAFA,aAAQ,GAAkC,IAAI,GAAG,EAAE,CAAC;QAGlD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,yBAAmB,EAAE,CAAC,CAAC;QACpD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,yBAAmB,EAAE,CAAC,CAAC;QACpD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,mCAAwB,EAAE,CAAC,CAAC;QAC9D,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,+BAAsB,EAAE,CAAC,CAAC;IAC5D,CAAC;IAED,kBAAkB,CAAC,OAA0B;QAC3C,MAAM,gBAAgB,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QAChE,IAAI,CAAC,gBAAgB;YACnB,OAAO;gBACL,UAAU,EAAE,KAAK;aAClB,CAAC;QACJ,OAAO,gBAAgB,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;IACtD,CAAC;IAED,mBAAmB,CAAC,OAA0B;QAC5C,MAAM,gBAAgB,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QAChE,IAAI,CAAC,CAAA,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,mBAAmB,CAAA;YAAE,OAAO;QACnD,OAAO,gBAAgB,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC;IACvD,CAAC;IAED,YAAY,CACV,QAA4B,EAC5B,IAAU,EACV,MAAc,EACd,MAAmC;;QAEnC,MAAM,gBAAgB,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QACzE,MAAA,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,YAAY,+CAA9B,gBAAgB,EAAiB,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACnE,CAAC;CACF;AAlCD,gDAkCC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { Tracer, Span } from '@opentelemetry/api';\nimport { ServiceExtension, RequestMetadata } from './ServiceExtension';\nimport { SqsServiceExtension } from './sqs';\nimport {\n AwsSdkInstrumentationConfig,\n NormalizedRequest,\n NormalizedResponse,\n} from '../types';\nimport { DynamodbServiceExtension } from './dynamodb';\nimport { SnsServiceExtension } from './sns';\nimport { LambdaServiceExtension } from './lambda';\n\nexport class ServicesExtensions implements ServiceExtension {\n services: Map<string, ServiceExtension> = new Map();\n\n constructor() {\n this.services.set('SQS', new SqsServiceExtension());\n this.services.set('SNS', new SnsServiceExtension());\n this.services.set('DynamoDB', new DynamodbServiceExtension());\n this.services.set('Lambda', new LambdaServiceExtension());\n }\n\n requestPreSpanHook(request: NormalizedRequest): RequestMetadata {\n const serviceExtension = this.services.get(request.serviceName);\n if (!serviceExtension)\n return {\n isIncoming: false,\n };\n return serviceExtension.requestPreSpanHook(request);\n }\n\n requestPostSpanHook(request: NormalizedRequest) {\n const serviceExtension = this.services.get(request.serviceName);\n if (!serviceExtension?.requestPostSpanHook) return;\n return serviceExtension.requestPostSpanHook(request);\n }\n\n responseHook(\n response: NormalizedResponse,\n span: Span,\n tracer: Tracer,\n config: AwsSdkInstrumentationConfig\n ) {\n const serviceExtension = this.services.get(response.request.serviceName);\n serviceExtension?.responseHook?.(response, span, tracer, config);\n }\n}\n"]}
1
+ {"version":3,"file":"ServicesExtensions.js","sourceRoot":"","sources":["../../../src/services/ServicesExtensions.ts"],"names":[],"mappings":";;;AAiBA,+BAA4C;AAM5C,yCAAsD;AACtD,+BAA4C;AAC5C,qCAAkD;AAElD,MAAa,kBAAkB;IAG7B;QAFA,aAAQ,GAAkC,IAAI,GAAG,EAAE,CAAC;QAGlD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,yBAAmB,EAAE,CAAC,CAAC;QACpD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,yBAAmB,EAAE,CAAC,CAAC;QACpD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,UAAU,EAAE,IAAI,mCAAwB,EAAE,CAAC,CAAC;QAC9D,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,+BAAsB,EAAE,CAAC,CAAC;IAC5D,CAAC;IAED,kBAAkB,CAChB,OAA0B,EAC1B,MAAmC,EACnC,IAAgB;QAEhB,MAAM,gBAAgB,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QAChE,IAAI,CAAC,gBAAgB;YACnB,OAAO;gBACL,UAAU,EAAE,KAAK;aAClB,CAAC;QACJ,OAAO,gBAAgB,CAAC,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IACpE,CAAC;IAED,mBAAmB,CAAC,OAA0B;QAC5C,MAAM,gBAAgB,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QAChE,IAAI,CAAC,CAAA,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,mBAAmB,CAAA;YAAE,OAAO;QACnD,OAAO,gBAAgB,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC;IACvD,CAAC;IAED,YAAY,CACV,QAA4B,EAC5B,IAAU,EACV,MAAc,EACd,MAAmC;;QAEnC,MAAM,gBAAgB,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QACzE,MAAA,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,YAAY,+CAA9B,gBAAgB,EAAiB,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACnE,CAAC;CACF;AAtCD,gDAsCC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { Tracer, Span, DiagLogger } from '@opentelemetry/api';\nimport { ServiceExtension, RequestMetadata } from './ServiceExtension';\nimport { SqsServiceExtension } from './sqs';\nimport {\n AwsSdkInstrumentationConfig,\n NormalizedRequest,\n NormalizedResponse,\n} from '../types';\nimport { DynamodbServiceExtension } from './dynamodb';\nimport { SnsServiceExtension } from './sns';\nimport { LambdaServiceExtension } from './lambda';\n\nexport class ServicesExtensions implements ServiceExtension {\n services: Map<string, ServiceExtension> = new Map();\n\n constructor() {\n this.services.set('SQS', new SqsServiceExtension());\n this.services.set('SNS', new SnsServiceExtension());\n this.services.set('DynamoDB', new DynamodbServiceExtension());\n this.services.set('Lambda', new LambdaServiceExtension());\n }\n\n requestPreSpanHook(\n request: NormalizedRequest,\n config: AwsSdkInstrumentationConfig,\n diag: DiagLogger\n ): RequestMetadata {\n const serviceExtension = this.services.get(request.serviceName);\n if (!serviceExtension)\n return {\n isIncoming: false,\n };\n return serviceExtension.requestPreSpanHook(request, config, diag);\n }\n\n requestPostSpanHook(request: NormalizedRequest) {\n const serviceExtension = this.services.get(request.serviceName);\n if (!serviceExtension?.requestPostSpanHook) return;\n return serviceExtension.requestPostSpanHook(request);\n }\n\n responseHook(\n response: NormalizedResponse,\n span: Span,\n tracer: Tracer,\n config: AwsSdkInstrumentationConfig\n ) {\n const serviceExtension = this.services.get(response.request.serviceName);\n serviceExtension?.responseHook?.(response, span, tracer, config);\n }\n}\n"]}
@@ -1,9 +1,9 @@
1
- import { Span, Tracer } from '@opentelemetry/api';
1
+ import { DiagLogger, Span, Tracer } from '@opentelemetry/api';
2
2
  import { RequestMetadata, ServiceExtension } from './ServiceExtension';
3
3
  import { AwsSdkInstrumentationConfig, NormalizedRequest, NormalizedResponse } from '../types';
4
4
  export declare class DynamodbServiceExtension implements ServiceExtension {
5
5
  toArray<T>(values: T | T[]): T[];
6
- requestPreSpanHook(normalizedRequest: NormalizedRequest): RequestMetadata;
6
+ requestPreSpanHook(normalizedRequest: NormalizedRequest, config: AwsSdkInstrumentationConfig, diag: DiagLogger): RequestMetadata;
7
7
  responseHook(response: NormalizedResponse, span: Span, _tracer: Tracer, _config: AwsSdkInstrumentationConfig): void;
8
8
  }
9
9
  //# sourceMappingURL=dynamodb.d.ts.map
@@ -22,7 +22,7 @@ class DynamodbServiceExtension {
22
22
  toArray(values) {
23
23
  return Array.isArray(values) ? values : [values];
24
24
  }
25
- requestPreSpanHook(normalizedRequest) {
25
+ requestPreSpanHook(normalizedRequest, config, diag) {
26
26
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
27
27
  const spanKind = api_1.SpanKind.CLIENT;
28
28
  let spanName;
@@ -32,8 +32,18 @@ class DynamodbServiceExtension {
32
32
  [semantic_conventions_1.SemanticAttributes.DB_SYSTEM]: semantic_conventions_1.DbSystemValues.DYNAMODB,
33
33
  [semantic_conventions_1.SemanticAttributes.DB_NAME]: (_a = normalizedRequest.commandInput) === null || _a === void 0 ? void 0 : _a.TableName,
34
34
  [semantic_conventions_1.SemanticAttributes.DB_OPERATION]: operation,
35
- [semantic_conventions_1.SemanticAttributes.DB_STATEMENT]: JSON.stringify(normalizedRequest.commandInput),
36
35
  };
36
+ if (config.dynamoDBStatementSerializer) {
37
+ try {
38
+ const sanitizedStatement = config.dynamoDBStatementSerializer(operation, normalizedRequest.commandInput);
39
+ if (typeof sanitizedStatement === 'string') {
40
+ spanAttributes[semantic_conventions_1.SemanticAttributes.DB_STATEMENT] = sanitizedStatement;
41
+ }
42
+ }
43
+ catch (err) {
44
+ diag.error('failed to sanitize DynamoDB statement', err);
45
+ }
46
+ }
37
47
  // normalizedRequest.commandInput.RequestItems) is undefined when no table names are returned
38
48
  // keys in this object are the table names
39
49
  if ((_b = normalizedRequest.commandInput) === null || _b === void 0 ? void 0 : _b.TableName) {
@@ -1 +1 @@
1
- {"version":3,"file":"dynamodb.js","sourceRoot":"","sources":["../../../src/services/dynamodb.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,4CAA4D;AAE5D,8EAG6C;AAO7C,MAAa,wBAAwB;IACnC,OAAO,CAAI,MAAe;QACxB,OAAO,KAAK,CAAC,OAAO,CAAC,MA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Content":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { Span, SpanKind, Tracer } from '@opentelemetry/api';\nimport { RequestMetadata, ServiceExtension } from './ServiceExtension';\nimport {\n DbSystemValues,\n SemanticAttributes,\n} from '@opentelemetry/semantic-conventions';\nimport {\n AwsSdkInstrumentationConfig,\n NormalizedRequest,\n NormalizedResponse,\n} from '../types';\n\nexport class DynamodbServiceExtension implements ServiceExtension {\n toArray<T>(values: T | T[]): T[] {\n return Array.isArray(values) ? values : [values];\n }\n\n requestPreSpanHook(normalizedRequest: NormalizedRequest): RequestMetadata {\n const spanKind: SpanKind = SpanKind.CLIENT;\n let spanName: string | undefined;\n const isIncoming = false;\n const operation = normalizedRequest.commandName;\n\n const spanAttributes = {\n [SemanticAttributes.DB_SYSTEM]: DbSystemValues.DYNAMODB,\n [SemanticAttributes.DB_NAME]: normalizedRequest.commandInput?.TableName,\n [SemanticAttributes.DB_OPERATION]: operation,\n [SemanticAttributes.DB_STATEMENT]: JSON.stringify(\n normalizedRequest.commandInput\n ),\n };\n\n // normalizedRequest.commandInput.RequestItems) is undefined when no table names are returned\n // keys in this object are the table names\n if (normalizedRequest.commandInput?.TableName) {\n // Necessary for commands with only 1 table name (example: CreateTable). Attribute is TableName not keys of RequestItems\n // single table name returned for operations like CreateTable\n spanAttributes[SemanticAttributes.AWS_DYNAMODB_TABLE_NAMES] = [\n normalizedRequest.commandInput.TableName,\n ];\n } else if (normalizedRequest.commandInput?.RequestItems) {\n spanAttributes[SemanticAttributes.AWS_DYNAMODB_TABLE_NAMES] = Object.keys(\n normalizedRequest.commandInput.RequestItems\n );\n }\n\n if (operation === 'CreateTable' || operation === 'UpdateTable') {\n // only check for ProvisionedThroughput since ReadCapacityUnits and WriteCapacity units are required attributes\n if (normalizedRequest.commandInput?.ProvisionedThroughput) {\n spanAttributes[\n SemanticAttributes.AWS_DYNAMODB_PROVISIONED_READ_CAPACITY\n ] =\n normalizedRequest.commandInput.ProvisionedThroughput.ReadCapacityUnits;\n spanAttributes[\n SemanticAttributes.AWS_DYNAMODB_PROVISIONED_WRITE_CAPACITY\n ] =\n normalizedRequest.commandInput.ProvisionedThroughput.WriteCapacityUnits;\n }\n }\n\n if (\n operation === 'GetItem' ||\n operation === 'Scan' ||\n operation === 'Query'\n ) {\n if (normalizedRequest.commandInput?.ConsistentRead) {\n spanAttributes[SemanticAttributes.AWS_DYNAMODB_CONSISTENT_READ] =\n normalizedRequest.commandInput.ConsistentRead;\n }\n }\n\n if (operation === 'Query' || operation === 'Scan') {\n if (normalizedRequest.commandInput?.ProjectionExpression) {\n spanAttributes[SemanticAttributes.AWS_DYNAMODB_PROJECTION] =\n normalizedRequest.commandInput.ProjectionExpression;\n }\n }\n\n if (operation === 'CreateTable') {\n if (normalizedRequest.commandInput?.GlobalSecondaryIndexes) {\n spanAttributes[\n SemanticAttributes.AWS_DYNAMODB_GLOBAL_SECONDARY_INDEXES\n ] = this.toArray(\n normalizedRequest.commandInput.GlobalSecondaryIndexes\n ).map((x: { [DictionaryKey: string]: any }) => JSON.stringify(x));\n }\n\n if (normalizedRequest.commandInput?.LocalSecondaryIndexes) {\n spanAttributes[\n SemanticAttributes.AWS_DYNAMODB_LOCAL_SECONDARY_INDEXES\n ] = this.toArray(\n normalizedRequest.commandInput.LocalSecondaryIndexes\n ).map((x: { [DictionaryKey: string]: any }) => JSON.stringify(x));\n }\n }\n\n if (\n operation === 'ListTables' ||\n operation === 'Query' ||\n operation === 'Scan'\n ) {\n if (normalizedRequest.commandInput?.Limit) {\n spanAttributes[SemanticAttributes.AWS_DYNAMODB_LIMIT] =\n normalizedRequest.commandInput.Limit;\n }\n }\n\n if (operation === 'ListTables') {\n if (normalizedRequest.commandInput?.ExclusiveStartTableName) {\n spanAttributes[SemanticAttributes.AWS_DYNAMODB_EXCLUSIVE_START_TABLE] =\n normalizedRequest.commandInput.ExclusiveStartTableName;\n }\n }\n\n if (operation === 'Query') {\n if (normalizedRequest.commandInput?.ScanIndexForward) {\n spanAttributes[SemanticAttributes.AWS_DYNAMODB_SCAN_FORWARD] =\n normalizedRequest.commandInput.ScanIndexForward;\n }\n\n if (normalizedRequest.commandInput?.IndexName) {\n spanAttributes[SemanticAttributes.AWS_DYNAMODB_INDEX_NAME] =\n normalizedRequest.commandInput.IndexName;\n }\n\n if (normalizedRequest.commandInput?.Select) {\n spanAttributes[SemanticAttributes.AWS_DYNAMODB_SELECT] =\n normalizedRequest.commandInput.Select;\n }\n }\n\n if (operation === 'Scan') {\n if (normalizedRequest.commandInput?.Segment) {\n spanAttributes[SemanticAttributes.AWS_DYNAMODB_SEGMENT] =\n normalizedRequest.commandInput?.Segment;\n }\n\n if (normalizedRequest.commandInput?.TotalSegments) {\n spanAttributes[SemanticAttributes.AWS_DYNAMODB_TOTAL_SEGMENTS] =\n normalizedRequest.commandInput?.TotalSegments;\n }\n\n if (normalizedRequest.commandInput?.IndexName) {\n spanAttributes[SemanticAttributes.AWS_DYNAMODB_INDEX_NAME] =\n normalizedRequest.commandInput.IndexName;\n }\n\n if (normalizedRequest.commandInput?.Select) {\n spanAttributes[SemanticAttributes.AWS_DYNAMODB_SELECT] =\n normalizedRequest.commandInput.Select;\n }\n }\n\n if (operation === 'UpdateTable') {\n if (normalizedRequest.commandInput?.AttributeDefinitions) {\n spanAttributes[SemanticAttributes.AWS_DYNAMODB_ATTRIBUTE_DEFINITIONS] =\n this.toArray(normalizedRequest.commandInput.AttributeDefinitions).map(\n (x: { [DictionaryKey: string]: any }) => JSON.stringify(x)\n );\n }\n\n if (normalizedRequest.commandInput?.GlobalSecondaryIndexUpdates) {\n spanAttributes[\n SemanticAttributes.AWS_DYNAMODB_GLOBAL_SECONDARY_INDEX_UPDATES\n ] = this.toArray(\n normalizedRequest.commandInput.GlobalSecondaryIndexUpdates\n ).map((x: { [DictionaryKey: string]: any }) => JSON.stringify(x));\n }\n }\n\n return {\n isIncoming,\n spanAttributes,\n spanKind,\n spanName,\n };\n }\n\n responseHook(\n response: NormalizedResponse,\n span: Span,\n _tracer: Tracer,\n _config: AwsSdkInstrumentationConfig\n ) {\n if (response.data?.ConsumedCapacity) {\n span.setAttribute(\n SemanticAttributes.AWS_DYNAMODB_CONSUMED_CAPACITY,\n toArray(response.data.ConsumedCapacity).map(\n (x: { [DictionaryKey: string]: any }) => JSON.stringify(x)\n )\n );\n }\n\n if (response.data?.ItemCollectionMetrics) {\n span.setAttribute(\n SemanticAttributes.AWS_DYNAMODB_ITEM_COLLECTION_METRICS,\n this.toArray(response.data.ItemCollectionMetrics).map(\n (x: { [DictionaryKey: string]: any }) => JSON.stringify(x)\n )\n );\n }\n\n if (response.data?.TableNames) {\n span.setAttribute(\n SemanticAttributes.AWS_DYNAMODB_TABLE_COUNT,\n response.data?.TableNames.length\n );\n }\n\n if (response.data?.Count) {\n span.setAttribute(\n SemanticAttributes.AWS_DYNAMODB_COUNT,\n response.data?.Count\n );\n }\n\n if (response.data?.ScannedCount) {\n span.setAttribute(\n SemanticAttributes.AWS_DYNAMODB_SCANNED_COUNT,\n response.data?.ScannedCount\n );\n }\n }\n}\n\nfunction toArray<T>(values: T | T[]): T[] {\n return Array.isArray(values) ? values : [values];\n}\n"]}
1
+ {"version":3,"file":"dynamodb.js","sourceRoot":"","sources":["../../../src/services/dynamodb.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,4CAAwE;AAExE,8EAG6C;AAO7C,MAAa,wBAAwB;IACnC,OAAO,CAAI,MAAe;QACxB,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,C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A0B,EAC7C,MAAA,QAAQ,CAAC,IAAI,0CAAE,YAAY,CAC5B,CAAC;SACH;IACH,CAAC;CACF;AAnOD,4DAmOC;AAED,SAAS,OAAO,CAAI,MAAe;IACjC,OAAO,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AACnD,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { DiagLogger, Span, SpanKind, Tracer } from '@opentelemetry/api';\nimport { RequestMetadata, ServiceExtension } from './ServiceExtension';\nimport {\n DbSystemValues,\n SemanticAttributes,\n} from '@opentelemetry/semantic-conventions';\nimport {\n AwsSdkInstrumentationConfig,\n NormalizedRequest,\n NormalizedResponse,\n} from '../types';\n\nexport class DynamodbServiceExtension implements ServiceExtension {\n toArray<T>(values: T | T[]): T[] {\n return Array.isArray(values) ? values : [values];\n }\n\n requestPreSpanHook(\n normalizedRequest: NormalizedRequest,\n config: AwsSdkInstrumentationConfig,\n diag: DiagLogger\n ): RequestMetadata {\n const spanKind: SpanKind = SpanKind.CLIENT;\n let spanName: string | undefined;\n const isIncoming = false;\n const operation = normalizedRequest.commandName;\n\n const spanAttributes = {\n [SemanticAttributes.DB_SYSTEM]: DbSystemValues.DYNAMODB,\n [SemanticAttributes.DB_NAME]: normalizedRequest.commandInput?.TableName,\n [SemanticAttributes.DB_OPERATION]: operation,\n };\n\n if (config.dynamoDBStatementSerializer) {\n try {\n const sanitizedStatement = config.dynamoDBStatementSerializer(\n operation,\n normalizedRequest.commandInput\n );\n\n if (typeof sanitizedStatement === 'string') {\n spanAttributes[SemanticAttributes.DB_STATEMENT] = sanitizedStatement;\n }\n } catch (err) {\n diag.error('failed to sanitize DynamoDB statement', err);\n }\n }\n\n // normalizedRequest.commandInput.RequestItems) is undefined when no table names are returned\n // keys in this object are the table names\n if (normalizedRequest.commandInput?.TableName) {\n // Necessary for commands with only 1 table name (example: CreateTable). Attribute is TableName not keys of RequestItems\n // single table name returned for operations like CreateTable\n spanAttributes[SemanticAttributes.AWS_DYNAMODB_TABLE_NAMES] = [\n normalizedRequest.commandInput.TableName,\n ];\n } else if (normalizedRequest.commandInput?.RequestItems) {\n spanAttributes[SemanticAttributes.AWS_DYNAMODB_TABLE_NAMES] = Object.keys(\n normalizedRequest.commandInput.RequestItems\n );\n }\n\n if (operation === 'CreateTable' || operation === 'UpdateTable') {\n // only check for ProvisionedThroughput since ReadCapacityUnits and WriteCapacity units are required attributes\n if (normalizedRequest.commandInput?.ProvisionedThroughput) {\n spanAttributes[\n SemanticAttributes.AWS_DYNAMODB_PROVISIONED_READ_CAPACITY\n ] =\n normalizedRequest.commandInput.ProvisionedThroughput.ReadCapacityUnits;\n spanAttributes[\n SemanticAttributes.AWS_DYNAMODB_PROVISIONED_WRITE_CAPACITY\n ] =\n normalizedRequest.commandInput.ProvisionedThroughput.WriteCapacityUnits;\n }\n }\n\n if (\n operation === 'GetItem' ||\n operation === 'Scan' ||\n operation === 'Query'\n ) {\n if (normalizedRequest.commandInput?.ConsistentRead) {\n spanAttributes[SemanticAttributes.AWS_DYNAMODB_CONSISTENT_READ] =\n normalizedRequest.commandInput.ConsistentRead;\n }\n }\n\n if (operation === 'Query' || operation === 'Scan') {\n if (normalizedRequest.commandInput?.ProjectionExpression) {\n spanAttributes[SemanticAttributes.AWS_DYNAMODB_PROJECTION] =\n normalizedRequest.commandInput.ProjectionExpression;\n }\n }\n\n if (operation === 'CreateTable') {\n if (normalizedRequest.commandInput?.GlobalSecondaryIndexes) {\n spanAttributes[\n SemanticAttributes.AWS_DYNAMODB_GLOBAL_SECONDARY_INDEXES\n ] = this.toArray(\n normalizedRequest.commandInput.GlobalSecondaryIndexes\n ).map((x: { [DictionaryKey: string]: any }) => JSON.stringify(x));\n }\n\n if (normalizedRequest.commandInput?.LocalSecondaryIndexes) {\n spanAttributes[\n SemanticAttributes.AWS_DYNAMODB_LOCAL_SECONDARY_INDEXES\n ] = this.toArray(\n normalizedRequest.commandInput.LocalSecondaryIndexes\n ).map((x: { [DictionaryKey: string]: any }) => JSON.stringify(x));\n }\n }\n\n if (\n operation === 'ListTables' ||\n operation === 'Query' ||\n operation === 'Scan'\n ) {\n if (normalizedRequest.commandInput?.Limit) {\n spanAttributes[SemanticAttributes.AWS_DYNAMODB_LIMIT] =\n normalizedRequest.commandInput.Limit;\n }\n }\n\n if (operation === 'ListTables') {\n if (normalizedRequest.commandInput?.ExclusiveStartTableName) {\n spanAttributes[SemanticAttributes.AWS_DYNAMODB_EXCLUSIVE_START_TABLE] =\n normalizedRequest.commandInput.ExclusiveStartTableName;\n }\n }\n\n if (operation === 'Query') {\n if (normalizedRequest.commandInput?.ScanIndexForward) {\n spanAttributes[SemanticAttributes.AWS_DYNAMODB_SCAN_FORWARD] =\n normalizedRequest.commandInput.ScanIndexForward;\n }\n\n if (normalizedRequest.commandInput?.IndexName) {\n spanAttributes[SemanticAttributes.AWS_DYNAMODB_INDEX_NAME] =\n normalizedRequest.commandInput.IndexName;\n }\n\n if (normalizedRequest.commandInput?.Select) {\n spanAttributes[SemanticAttributes.AWS_DYNAMODB_SELECT] =\n normalizedRequest.commandInput.Select;\n }\n }\n\n if (operation === 'Scan') {\n if (normalizedRequest.commandInput?.Segment) {\n spanAttributes[SemanticAttributes.AWS_DYNAMODB_SEGMENT] =\n normalizedRequest.commandInput?.Segment;\n }\n\n if (normalizedRequest.commandInput?.TotalSegments) {\n spanAttributes[SemanticAttributes.AWS_DYNAMODB_TOTAL_SEGMENTS] =\n normalizedRequest.commandInput?.TotalSegments;\n }\n\n if (normalizedRequest.commandInput?.IndexName) {\n spanAttributes[SemanticAttributes.AWS_DYNAMODB_INDEX_NAME] =\n normalizedRequest.commandInput.IndexName;\n }\n\n if (normalizedRequest.commandInput?.Select) {\n spanAttributes[SemanticAttributes.AWS_DYNAMODB_SELECT] =\n normalizedRequest.commandInput.Select;\n }\n }\n\n if (operation === 'UpdateTable') {\n if (normalizedRequest.commandInput?.AttributeDefinitions) {\n spanAttributes[SemanticAttributes.AWS_DYNAMODB_ATTRIBUTE_DEFINITIONS] =\n this.toArray(normalizedRequest.commandInput.AttributeDefinitions).map(\n (x: { [DictionaryKey: string]: any }) => JSON.stringify(x)\n );\n }\n\n if (normalizedRequest.commandInput?.GlobalSecondaryIndexUpdates) {\n spanAttributes[\n SemanticAttributes.AWS_DYNAMODB_GLOBAL_SECONDARY_INDEX_UPDATES\n ] = this.toArray(\n normalizedRequest.commandInput.GlobalSecondaryIndexUpdates\n ).map((x: { [DictionaryKey: string]: any }) => JSON.stringify(x));\n }\n }\n\n return {\n isIncoming,\n spanAttributes,\n spanKind,\n spanName,\n };\n }\n\n responseHook(\n response: NormalizedResponse,\n span: Span,\n _tracer: Tracer,\n _config: AwsSdkInstrumentationConfig\n ) {\n if (response.data?.ConsumedCapacity) {\n span.setAttribute(\n SemanticAttributes.AWS_DYNAMODB_CONSUMED_CAPACITY,\n toArray(response.data.ConsumedCapacity).map(\n (x: { [DictionaryKey: string]: any }) => JSON.stringify(x)\n )\n );\n }\n\n if (response.data?.ItemCollectionMetrics) {\n span.setAttribute(\n SemanticAttributes.AWS_DYNAMODB_ITEM_COLLECTION_METRICS,\n this.toArray(response.data.ItemCollectionMetrics).map(\n (x: { [DictionaryKey: string]: any }) => JSON.stringify(x)\n )\n );\n }\n\n if (response.data?.TableNames) {\n span.setAttribute(\n SemanticAttributes.AWS_DYNAMODB_TABLE_COUNT,\n response.data?.TableNames.length\n );\n }\n\n if (response.data?.Count) {\n span.setAttribute(\n SemanticAttributes.AWS_DYNAMODB_COUNT,\n response.data?.Count\n );\n }\n\n if (response.data?.ScannedCount) {\n span.setAttribute(\n SemanticAttributes.AWS_DYNAMODB_SCANNED_COUNT,\n response.data?.ScannedCount\n );\n }\n }\n}\n\nfunction toArray<T>(values: T | T[]): T[] {\n return Array.isArray(values) ? values : [values];\n}\n"]}
@@ -2,7 +2,7 @@ import { Span, Tracer } from '@opentelemetry/api';
2
2
  import { AwsSdkInstrumentationConfig, NormalizedRequest, NormalizedResponse } from '../types';
3
3
  import { RequestMetadata, ServiceExtension } from './ServiceExtension';
4
4
  export declare class LambdaServiceExtension implements ServiceExtension {
5
- requestPreSpanHook(request: NormalizedRequest): RequestMetadata;
5
+ requestPreSpanHook(request: NormalizedRequest, _config: AwsSdkInstrumentationConfig): RequestMetadata;
6
6
  requestPostSpanHook: (request: NormalizedRequest) => void;
7
7
  responseHook(response: NormalizedResponse, span: Span, tracer: Tracer, config: AwsSdkInstrumentationConfig): void;
8
8
  extractFunctionName: (commandInput: Record<string, any>) => string;
@@ -39,7 +39,7 @@ class LambdaServiceExtension {
39
39
  return commandInput === null || commandInput === void 0 ? void 0 : commandInput.FunctionName;
40
40
  };
41
41
  }
42
- requestPreSpanHook(request) {
42
+ requestPreSpanHook(request, _config) {
43
43
  const functionName = this.extractFunctionName(request.commandInput);
44
44
  let spanAttributes = {};
45
45
  let spanName;
@@ -1 +1 @@
1
- {"version":3,"file":"lambda.js","sourceRoot":"","sources":["../../../src/services/lambda.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,4CAM4B;AAC5B,8EAAyE;AAOzE,4CAA0D;AAE1D,MAAM,cAAc;;AACK,qBAAM,GAAW,QAAQ,CAAC;AAGnD,MAAa,sBAAsB;IAAnC;QA4BE,wBAAmB,GAAG,CAAC,OAA0B,EAAE,EAAE;YACnD,QAAQ,OAAO,CAAC,WAAW,EAAE;gBAC3B,KAAK,cAAc,CAAC,MAAM;oBACxB;wBACE,IAAI,OAAO,CAAC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AC;iBACH;gBACD,MAAM;SACT;IACH,CAAC;CAKF;AA/DD,wDA+DC;AAED,MAAM,8BAA8B,GAAG,CACrC,aAAiC,EACb,EAAE;IACtB,IAAI;QACF,MAAM,iBAAiB,GAAG,EAAE,CAAC;QAC7B,iBAAW,CAAC,MAAM,CAAC,aAAO,CAAC,MAAM,EAAE,EAAE,iBAAiB,CAAC,CAAC;QAExD,MAAM,mBAAmB,GAAG,aAAa;YACvC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;YACnE,CAAC,CAAC,EAAE,CAAC;QAEP,MAAM,oBAAoB,mCACrB,mBAAmB,KACtB,MAAM,kCACD,mBAAmB,CAAC,MAAM,GAC1B,iBAAiB,IAEvB,CAAC;QAEF,MAAM,oBAAoB,GAAG,MAAM,CAAC,IAAI,CACtC,IAAI,CAAC,SAAS,CAAC,oBAAoB,CAAC,CACrC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAErB,8EAA8E;QAC9E,0FAA0F;QAC1F,IAAI,oBAAoB,CAAC,MAAM,GAAG,IAAI,EAAE;YACtC,UAAI,CAAC,IAAI,CACP,6HAA6H,CAC9H,CAAC;YACF,OAAO,aAAa,CAAC;SACtB;QAED,OAAO,oBAAoB,CAAC;KAC7B;IAAC,OAAO,CAAC,EAAE;QACV,UAAI,CAAC,KAAK,CACR,4EAA4E,EAC5E,CAAC,CACF,CAAC;QACF,OAAO,aAAa,CAAC;KACtB;AACH,CAAC,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n Span,\n SpanKind,\n Tracer,\n diag,\n SpanAttributes,\n} from '@opentelemetry/api';\nimport { SemanticAttributes } from '@opentelemetry/semantic-conventions';\nimport {\n AwsSdkInstrumentationConfig,\n NormalizedRequest,\n NormalizedResponse,\n} from '../types';\nimport { RequestMetadata, ServiceExtension } from './ServiceExtension';\nimport { context, propagation } from '@opentelemetry/api';\n\nclass LambdaCommands {\n public static readonly Invoke: string = 'Invoke';\n}\n\nexport class LambdaServiceExtension implements ServiceExtension {\n requestPreSpanHook(request: NormalizedRequest): RequestMetadata {\n const functionName = this.extractFunctionName(request.commandInput);\n\n let spanAttributes: SpanAttributes = {};\n let spanName: string | undefined;\n\n switch (request.commandName) {\n case 'Invoke':\n spanAttributes = {\n [SemanticAttributes.FAAS_INVOKED_NAME]: functionName,\n [SemanticAttributes.FAAS_INVOKED_PROVIDER]: 'aws',\n };\n if (request.region) {\n spanAttributes[SemanticAttributes.FAAS_INVOKED_REGION] =\n request.region;\n }\n spanName = `${functionName} ${LambdaCommands.Invoke}`;\n break;\n }\n return {\n isIncoming: false,\n spanAttributes,\n spanKind: SpanKind.CLIENT,\n spanName,\n };\n }\n\n requestPostSpanHook = (request: NormalizedRequest) => {\n switch (request.commandName) {\n case LambdaCommands.Invoke:\n {\n if (request.commandInput) {\n request.commandInput.ClientContext = injectLambdaPropagationContext(\n request.commandInput.ClientContext\n );\n }\n }\n break;\n }\n };\n\n responseHook(\n response: NormalizedResponse,\n span: Span,\n tracer: Tracer,\n config: AwsSdkInstrumentationConfig\n ) {\n switch (response.request.commandName) {\n case LambdaCommands.Invoke:\n {\n span.setAttribute(\n SemanticAttributes.FAAS_EXECUTION,\n response.requestId\n );\n }\n break;\n }\n }\n\n extractFunctionName = (commandInput: Record<string, any>): string => {\n return commandInput?.FunctionName;\n };\n}\n\nconst injectLambdaPropagationContext = (\n clientContext: string | undefined\n): string | undefined => {\n try {\n const propagatedContext = {};\n propagation.inject(context.active(), propagatedContext);\n\n const parsedClientContext = clientContext\n ? JSON.parse(Buffer.from(clientContext, 'base64').toString('utf8'))\n : {};\n\n const updatedClientContext = {\n ...parsedClientContext,\n Custom: {\n ...parsedClientContext.Custom,\n ...propagatedContext,\n },\n };\n\n const encodedClientContext = Buffer.from(\n JSON.stringify(updatedClientContext)\n ).toString('base64');\n\n // The length of client context is capped at 3583 bytes of base64 encoded data\n // (https://docs.aws.amazon.com/lambda/latest/dg/API_Invoke.html#API_Invoke_RequestSyntax)\n if (encodedClientContext.length > 3583) {\n diag.warn(\n 'lambda instrumentation: cannot set context propagation on lambda invoke parameters due to ClientContext length limitations.'\n );\n return clientContext;\n }\n\n return encodedClientContext;\n } catch (e) {\n diag.debug(\n 'lambda instrumentation: failed to set context propagation on ClientContext',\n e\n );\n return clientContext;\n }\n};\n"]}
1
+ {"version":3,"file":"lambda.js","sourceRoot":"","sources":["../../../src/services/lambda.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,4CAM4B;AAC5B,8EAAyE;AAOzE,4CAA0D;AAE1D,MAAM,cAAc;;AACK,qBAAM,GAAW,QAAQ,CAAC;AAGnD,MAAa,sBAAsB;IAAnC;QA+BE,wBAAmB,GAAG,CAAC,OAA0B,EAAE,EAAE;YACnD,QAAQ,OAAO,CAAC,WAAW,EAAE;gBAC3B,KAAK,cAAc,CAAC,MAAM;oBACxB;wBACE,IAAI,OAAO,CAAC,YAAY,EAAE;4BACxB,OAAO,CAAC,YAAY,CAAC,aAAa,GAAG,8BAA8B,CACjE,OAAO,CAAC,YAAY,CAAC,aAAa,CACnC,CAAC;yBACH;qBACF;oBACD,MAAM;aACT;QACH,CAAC,CAAC;QAoBF,wBAAmB,GAAG,CAAC,YAAiC,EAAU,EAAE;YAClE,OAAO,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,YAAY,CAAC;QACpC,CAAC,CAAC;IACJ,CAAC;IAjEC,kBAAkB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C,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;YACnE,CAAC,CAAC,EAAE,CAAC;QAEP,MAAM,oBAAoB,mCACrB,mBAAmB,KACtB,MAAM,kCACD,mBAAmB,CAAC,MAAM,GAC1B,iBAAiB,IAEvB,CAAC;QAEF,MAAM,oBAAoB,GAAG,MAAM,CAAC,IAAI,CACtC,IAAI,CAAC,SAAS,CAAC,oBAAoB,CAAC,CACrC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAErB,8EAA8E;QAC9E,0FAA0F;QAC1F,IAAI,oBAAoB,CAAC,MAAM,GAAG,IAAI,EAAE;YACtC,UAAI,CAAC,IAAI,CACP,6HAA6H,CAC9H,CAAC;YACF,OAAO,aAAa,CAAC;SACtB;QAED,OAAO,oBAAoB,CAAC;KAC7B;IAAC,OAAO,CAAC,EAAE;QACV,UAAI,CAAC,KAAK,CACR,4EAA4E,EAC5E,CAAC,CACF,CAAC;QACF,OAAO,aAAa,CAAC;KACtB;AACH,CAAC,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n Span,\n SpanKind,\n Tracer,\n diag,\n SpanAttributes,\n} from '@opentelemetry/api';\nimport { SemanticAttributes } from '@opentelemetry/semantic-conventions';\nimport {\n AwsSdkInstrumentationConfig,\n NormalizedRequest,\n NormalizedResponse,\n} from '../types';\nimport { RequestMetadata, ServiceExtension } from './ServiceExtension';\nimport { context, propagation } from '@opentelemetry/api';\n\nclass LambdaCommands {\n public static readonly Invoke: string = 'Invoke';\n}\n\nexport class LambdaServiceExtension implements ServiceExtension {\n requestPreSpanHook(\n request: NormalizedRequest,\n _config: AwsSdkInstrumentationConfig\n ): RequestMetadata {\n const functionName = this.extractFunctionName(request.commandInput);\n\n let spanAttributes: SpanAttributes = {};\n let spanName: string | undefined;\n\n switch (request.commandName) {\n case 'Invoke':\n spanAttributes = {\n [SemanticAttributes.FAAS_INVOKED_NAME]: functionName,\n [SemanticAttributes.FAAS_INVOKED_PROVIDER]: 'aws',\n };\n if (request.region) {\n spanAttributes[SemanticAttributes.FAAS_INVOKED_REGION] =\n request.region;\n }\n spanName = `${functionName} ${LambdaCommands.Invoke}`;\n break;\n }\n return {\n isIncoming: false,\n spanAttributes,\n spanKind: SpanKind.CLIENT,\n spanName,\n };\n }\n\n requestPostSpanHook = (request: NormalizedRequest) => {\n switch (request.commandName) {\n case LambdaCommands.Invoke:\n {\n if (request.commandInput) {\n request.commandInput.ClientContext = injectLambdaPropagationContext(\n request.commandInput.ClientContext\n );\n }\n }\n break;\n }\n };\n\n responseHook(\n response: NormalizedResponse,\n span: Span,\n tracer: Tracer,\n config: AwsSdkInstrumentationConfig\n ) {\n switch (response.request.commandName) {\n case LambdaCommands.Invoke:\n {\n span.setAttribute(\n SemanticAttributes.FAAS_EXECUTION,\n response.requestId\n );\n }\n break;\n }\n }\n\n extractFunctionName = (commandInput: Record<string, any>): string => {\n return commandInput?.FunctionName;\n };\n}\n\nconst injectLambdaPropagationContext = (\n clientContext: string | undefined\n): string | undefined => {\n try {\n const propagatedContext = {};\n propagation.inject(context.active(), propagatedContext);\n\n const parsedClientContext = clientContext\n ? JSON.parse(Buffer.from(clientContext, 'base64').toString('utf8'))\n : {};\n\n const updatedClientContext = {\n ...parsedClientContext,\n Custom: {\n ...parsedClientContext.Custom,\n ...propagatedContext,\n },\n };\n\n const encodedClientContext = Buffer.from(\n JSON.stringify(updatedClientContext)\n ).toString('base64');\n\n // The length of client context is capped at 3583 bytes of base64 encoded data\n // (https://docs.aws.amazon.com/lambda/latest/dg/API_Invoke.html#API_Invoke_RequestSyntax)\n if (encodedClientContext.length > 3583) {\n diag.warn(\n 'lambda instrumentation: cannot set context propagation on lambda invoke parameters due to ClientContext length limitations.'\n );\n return clientContext;\n }\n\n return encodedClientContext;\n } catch (e) {\n diag.debug(\n 'lambda instrumentation: failed to set context propagation on ClientContext',\n e\n );\n return clientContext;\n }\n};\n"]}
@@ -2,7 +2,7 @@ import { Span, Tracer } from '@opentelemetry/api';
2
2
  import { NormalizedRequest, NormalizedResponse, AwsSdkInstrumentationConfig } from '../types';
3
3
  import { RequestMetadata, ServiceExtension } from './ServiceExtension';
4
4
  export declare class SnsServiceExtension implements ServiceExtension {
5
- requestPreSpanHook(request: NormalizedRequest): RequestMetadata;
5
+ requestPreSpanHook(request: NormalizedRequest, _config: AwsSdkInstrumentationConfig): RequestMetadata;
6
6
  requestPostSpanHook(request: NormalizedRequest): void;
7
7
  responseHook(response: NormalizedResponse, span: Span, tracer: Tracer, config: AwsSdkInstrumentationConfig): void;
8
8
  extractDestinationName(topicArn: string, targetArn: string, phoneNumber: string): string;
@@ -20,7 +20,7 @@ const api_1 = require("@opentelemetry/api");
20
20
  const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
21
21
  const MessageAttributes_1 = require("./MessageAttributes");
22
22
  class SnsServiceExtension {
23
- requestPreSpanHook(request) {
23
+ requestPreSpanHook(request, _config) {
24
24
  let spanKind = api_1.SpanKind.CLIENT;
25
25
  let spanName = `SNS ${request.commandName}`;
26
26
  const spanAttributes = {
@@ -33,6 +33,9 @@ class SnsServiceExtension {
33
33
  const { TopicArn, TargetArn, PhoneNumber } = request.commandInput;
34
34
  spanAttributes[semantic_conventions_1.SemanticAttributes.MESSAGING_DESTINATION] =
35
35
  this.extractDestinationName(TopicArn, TargetArn, PhoneNumber);
36
+ // ToDO: Use SpanAttributes.MESSAGING_DESTINATION_NAME when implemented
37
+ spanAttributes['messaging.destination.name'] =
38
+ TopicArn || TargetArn || PhoneNumber || 'unknown';
36
39
  spanName = `${PhoneNumber
37
40
  ? 'phone_number'
38
41
  : spanAttributes[semantic_conventions_1.SemanticAttributes.MESSAGING_DESTINATION]} send`;
@@ -1 +1 @@
1
- {"version":3,"file":"sns.js","sourceRoot":"","sources":["../../../src/services/sns.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,4CAA4D;AAC5D,8EAG6C;AAM7C,2DAA+D;AAG/D,MAAa,mBAAmB;IAC9B,kBAAkB,CAAC,OAA0B;QAC3C,IAAI,QAAQ,GAAa,cAAQ,CAAC,MAAM,CAAC;QACzC,IAAI,QAAQ,GAAG,OAAO,OAAO,CAAC,WAAW,EAAE,CAAC;QAC5C,MAAM,cAAc,GAAG;YACrB,CAAC,yCAAkB,CAAC,gBAAgB,CAAC,EAAE,SAAS;SACjD,CAAC;QAEF,IAAI,OAAO,CAAC,WAAW,KAAK,SAAS,EAAE;YACrC,QAAQ,GAAG,cAAQ,CAAC,QAAQ,CAAC;YAE7B,cAAc,CAAC,yCAAkB,CAAC,0BAA0B,CAAC;gBAC3D,qDAA8B,CAAC,KAAK,CAAC;YACvC,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,YAAY,CAAC;YAClE,cAAc,CAAC,yCAAkB,CAAC,qBAAqB,CAAC;gBACtD,IAAI,CAAC,sBAAsB,CAAC,QAAQ,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC;YAEhE,QAAQ,GAAG,GACT,WAAW;gBACT,CAAC,CAAC,cAAc;gBAChB,CAAC,CAAC,cAAc,CAAC,yCAAkB,CAAC,qBAAqB,CAC7D,OAAO,CAAC;SACT;QAED,OAAO;YACL,UAAU,EAAE,KAAK;YACjB,cAAc;YACd,QAAQ;YACR,QAAQ;SACT,CAAC;IACJ,CAAC;IAED,mBAAmB,CAAC,OAA0B;;QAC5C,IAAI,OAAO,CAAC,WAAW,KAAK,SAAS,EAAE;YACrC,MAAM,qBAAqB,GACzB,MAAA,OAAO,CAAC,YAAY,CAAC,mBAAmB,CAAC,mCAAI,EAAE,CAAC;YAClD,IAAI,qBAAqB,EAAE;gBACzB,OAAO,CAAC,YAAY,CAAC,mBAAmB,CAAC,GAAG,IAAA,4CAAwB,EAClE,qBAAqB,CACtB,CAAC;aACH;SACF;IACH,CAAC;IAED,YAAY,CACV,QAA4B,EAC5B,IAAU,EACV,MAAc,EACd,MAAmC,IAC5B,CAAC;IAEV,sBAAsB,CACpB,QAAgB,EAChB,SAAiB,EACjB,WAAmB;QAEnB,IAAI,QAAQ,IAAI,SAAS,EAAE;YACzB,MAAM,GAAG,GAAG,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,SAAS,CAAC;YAClC,IAAI;gBACF,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;aAC7C;YAAC,OAAO,GAAG,EAAE;gBACZ,OAAO,GAAG,CAAC;aACZ;SACF;aAAM,IAAI,WAAW,EAAE;YACtB,OAAO,WAAW,CAAC;SACpB;aAAM;YACL,OAAO,SAAS,CAAC;SAClB;IACH,CAAC;CACF;AArED,kDAqEC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { Span, Tracer, SpanKind } from '@opentelemetry/api';\nimport {\n MessagingDestinationKindValues,\n SemanticAttributes,\n} from '@opentelemetry/semantic-conventions';\nimport {\n NormalizedRequest,\n NormalizedResponse,\n AwsSdkInstrumentationConfig,\n} from '../types';\nimport { injectPropagationContext } from './MessageAttributes';\nimport { RequestMetadata, ServiceExtension } from './ServiceExtension';\n\nexport class SnsServiceExtension implements ServiceExtension {\n requestPreSpanHook(request: NormalizedRequest): RequestMetadata {\n let spanKind: SpanKind = SpanKind.CLIENT;\n let spanName = `SNS ${request.commandName}`;\n const spanAttributes = {\n [SemanticAttributes.MESSAGING_SYSTEM]: 'aws.sns',\n };\n\n if (request.commandName === 'Publish') {\n spanKind = SpanKind.PRODUCER;\n\n spanAttributes[SemanticAttributes.MESSAGING_DESTINATION_KIND] =\n MessagingDestinationKindValues.TOPIC;\n const { TopicArn, TargetArn, PhoneNumber } = request.commandInput;\n spanAttributes[SemanticAttributes.MESSAGING_DESTINATION] =\n this.extractDestinationName(TopicArn, TargetArn, PhoneNumber);\n\n spanName = `${\n PhoneNumber\n ? 'phone_number'\n : spanAttributes[SemanticAttributes.MESSAGING_DESTINATION]\n } send`;\n }\n\n return {\n isIncoming: false,\n spanAttributes,\n spanKind,\n spanName,\n };\n }\n\n requestPostSpanHook(request: NormalizedRequest): void {\n if (request.commandName === 'Publish') {\n const origMessageAttributes =\n request.commandInput['MessageAttributes'] ?? {};\n if (origMessageAttributes) {\n request.commandInput['MessageAttributes'] = injectPropagationContext(\n origMessageAttributes\n );\n }\n }\n }\n\n responseHook(\n response: NormalizedResponse,\n span: Span,\n tracer: Tracer,\n config: AwsSdkInstrumentationConfig\n ): void {}\n\n extractDestinationName(\n topicArn: string,\n targetArn: string,\n phoneNumber: string\n ): string {\n if (topicArn || targetArn) {\n const arn = topicArn ?? targetArn;\n try {\n return arn.substr(arn.lastIndexOf(':') + 1);\n } catch (err) {\n return arn;\n }\n } else if (phoneNumber) {\n return phoneNumber;\n } else {\n return 'unknown';\n }\n }\n}\n"]}
1
+ {"version":3,"file":"sns.js","sourceRoot":"","sources":["../../../src/services/sns.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,4CAA4D;AAC5D,8EAG6C;AAM7C,2DAA+D;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AAA,4CAAwB,EAClE,qBAAqB,CACtB,CAAC;aACH;SACF;IACH,CAAC;IAED,YAAY,CACV,QAA4B,EAC5B,IAAU,EACV,MAAc,EACd,MAAmC,IAC5B,CAAC;IAEV,sBAAsB,CACpB,QAAgB,EAChB,SAAiB,EACjB,WAAmB;QAEnB,IAAI,QAAQ,IAAI,SAAS,EAAE;YACzB,MAAM,GAAG,GAAG,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,SAAS,CAAC;YAClC,IAAI;gBACF,OAAO,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;aAC7C;YAAC,OAAO,GAAG,EAAE;gBACZ,OAAO,GAAG,CAAC;aACZ;SACF;aAAM,IAAI,WAAW,EAAE;YACtB,OAAO,WAAW,CAAC;SACpB;aAAM;YACL,OAAO,SAAS,CAAC;SAClB;IACH,CAAC;CACF;AA3ED,kDA2EC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { Span, Tracer, SpanKind } from '@opentelemetry/api';\nimport {\n MessagingDestinationKindValues,\n SemanticAttributes,\n} from '@opentelemetry/semantic-conventions';\nimport {\n NormalizedRequest,\n NormalizedResponse,\n AwsSdkInstrumentationConfig,\n} from '../types';\nimport { injectPropagationContext } from './MessageAttributes';\nimport { RequestMetadata, ServiceExtension } from './ServiceExtension';\n\nexport class SnsServiceExtension implements ServiceExtension {\n requestPreSpanHook(\n request: NormalizedRequest,\n _config: AwsSdkInstrumentationConfig\n ): RequestMetadata {\n let spanKind: SpanKind = SpanKind.CLIENT;\n let spanName = `SNS ${request.commandName}`;\n const spanAttributes = {\n [SemanticAttributes.MESSAGING_SYSTEM]: 'aws.sns',\n };\n\n if (request.commandName === 'Publish') {\n spanKind = SpanKind.PRODUCER;\n\n spanAttributes[SemanticAttributes.MESSAGING_DESTINATION_KIND] =\n MessagingDestinationKindValues.TOPIC;\n const { TopicArn, TargetArn, PhoneNumber } = request.commandInput;\n spanAttributes[SemanticAttributes.MESSAGING_DESTINATION] =\n this.extractDestinationName(TopicArn, TargetArn, PhoneNumber);\n // ToDO: Use SpanAttributes.MESSAGING_DESTINATION_NAME when implemented\n spanAttributes['messaging.destination.name'] =\n TopicArn || TargetArn || PhoneNumber || 'unknown';\n\n spanName = `${\n PhoneNumber\n ? 'phone_number'\n : spanAttributes[SemanticAttributes.MESSAGING_DESTINATION]\n } send`;\n }\n\n return {\n isIncoming: false,\n spanAttributes,\n spanKind,\n spanName,\n };\n }\n\n requestPostSpanHook(request: NormalizedRequest): void {\n if (request.commandName === 'Publish') {\n const origMessageAttributes =\n request.commandInput['MessageAttributes'] ?? {};\n if (origMessageAttributes) {\n request.commandInput['MessageAttributes'] = injectPropagationContext(\n origMessageAttributes\n );\n }\n }\n }\n\n responseHook(\n response: NormalizedResponse,\n span: Span,\n tracer: Tracer,\n config: AwsSdkInstrumentationConfig\n ): void {}\n\n extractDestinationName(\n topicArn: string,\n targetArn: string,\n phoneNumber: string\n ): string {\n if (topicArn || targetArn) {\n const arn = topicArn ?? targetArn;\n try {\n return arn.substr(arn.lastIndexOf(':') + 1);\n } catch (err) {\n return arn;\n }\n } else if (phoneNumber) {\n return phoneNumber;\n } else {\n return 'unknown';\n }\n }\n}\n"]}
@@ -2,7 +2,7 @@ import { Tracer, Span } from '@opentelemetry/api';
2
2
  import { RequestMetadata, ServiceExtension } from './ServiceExtension';
3
3
  import { AwsSdkInstrumentationConfig, NormalizedRequest, NormalizedResponse } from '../types';
4
4
  export declare class SqsServiceExtension implements ServiceExtension {
5
- requestPreSpanHook(request: NormalizedRequest): RequestMetadata;
5
+ requestPreSpanHook(request: NormalizedRequest, _config: AwsSdkInstrumentationConfig): RequestMetadata;
6
6
  requestPostSpanHook: (request: NormalizedRequest) => void;
7
7
  responseHook: (response: NormalizedResponse, span: Span, tracer: Tracer, config: AwsSdkInstrumentationConfig) => void;
8
8
  extractQueueUrl: (commandInput: Record<string, any>) => string;
@@ -94,7 +94,7 @@ class SqsServiceExtension {
94
94
  return segments[segments.length - 1];
95
95
  };
96
96
  }
97
- requestPreSpanHook(request) {
97
+ requestPreSpanHook(request, _config) {
98
98
  const queueUrl = this.extractQueueUrl(request.commandInput);
99
99
  const queueName = this.extractQueueNameFromUrl(queueUrl);
100
100
  let spanKind = api_1.SpanKind.CLIENT;
@@ -1 +1 @@
1
- {"version":3,"file":"sqs.js","sourceRoot":"","sources":["../../../src/services/sqs.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,4CAQ4B;AAC5B,wEAAqE;AAQrE,8EAI6C;AAC7C,2DAK6B;AAE7B,MAAa,mBAAmB;IAAhC;QAiDE,wBAAmB,GAAG,CAAC,OAA0B,EAAE,EAAE;;YACnD,QAAQ,OAAO,CAAC,WAAW,EAAE;gBAC3B,KAAK,aAAa;oBAChB;wBACE,MAAM,qBAAqB,GACzB,MAAA,OAAO,CAAC,YAAY,CAAC,mBAAmB,CAAC,mCAAI,EAAE,CAAC;wBAClD,IAAI,qBAAqB,EAAE;4BACzB,OAAO,CAAC,YAAY,CAAC,mBAAmB,CAAC;gCACvC,IAAA,4CAAwB,EAAC,qBAAqB,CAAC,CAAC;yBACnD;qBACF;oBACD,MAAM;gBAER,KAAK,kBAAkB;oBACrB;wBACE,MAAA,MAAA,OAAO,CAAC,YAAY,0CAAE,OAAO,0CAAE,OAAO,CACpC,CAAC,aAA+C,EAAE,EAAE;;4BAClD,aAAa,CAAC,iBAAiB,GAAG,IAAA,4CAAwB,EACxD,MAAA,aAAa,CAAC,iBAAiB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AC;QAC5D,MAAM,SAAS,GAAG,IAAI,CAAC,uBAAuB,CAAC,QAAQ,CAAC,CAAC;QACzD,IAAI,QAAQ,GAAa,cAAQ,CAAC,MAAM,CAAC;QACzC,IAAI,QAA4B,CAAC;QAEjC,MAAM,cAAc,GAAG;YACrB,CAAC,yCAAkB,CAAC,gBAAgB,CAAC,EAAE,SAAS;YAChD,CAAC,yCAAkB,CAAC,0BAA0B,CAAC,EAC7C,qDAA8B,CAAC,KAAK;YACtC,CAAC,yCAAkB,CAAC,qBAAqB,CAAC,EAAE,SAAS;YACrD,CAAC,yCAAkB,CAAC,aAAa,CAAC,EAAE,QAAQ;SAC7C,CAAC;QAEF,IAAI,UAAU,GAAG,KAAK,CAAC;QAEvB,QAAQ,OAAO,CAAC,WAAW,EAAE;YAC3B,KAAK,gBAAgB;gBACnB;oBACE,UAAU,GAAG,IAAI,CAAC;oBAClB,QAAQ,GAAG,cAAQ,CAAC,QAAQ,CAAC;oBAC7B,QAAQ,GAAG,GAAG,SAAS,UAAU,CAAC;oBAClC,cAAc,CAAC,yCAAkB,CAAC,mBAAmB,CAAC;wBACpD,+CAAwB,CAAC,OAAO,CAAC;oBAEnC,OAAO,CAAC,YAAY,CAAC,qBAAqB;wBACxC,IAAA,wDAAoC,EAClC,OAAO,CAAC,YAAY,CAAC,qBAAqB,EAC1C,iBAAW,CAAC,MAAM,EAAE,CACrB,CAAC;iBACL;gBACD,MAAM;YAER,KAAK,aAAa,CAAC;YACnB,KAAK,kBAAkB;gBACrB,QAAQ,GAAG,cAAQ,CAAC,QAAQ,CAAC;gBAC7B,QAAQ,GAAG,GAAG,SAAS,OAAO,CAAC;gBAC/B,MAAM;SACT;QAED,OAAO;YACL,UAAU;YACV,cAAc;YACd,QAAQ;YACR,QAAQ;SACT,CAAC;IACJ,CAAC;CAyGF;AAxJD,kDAwJC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n Tracer,\n SpanKind,\n Span,\n propagation,\n trace,\n context,\n ROOT_CONTEXT,\n} from '@opentelemetry/api';\nimport { pubsubPropagation } from '@opentelemetry/propagation-utils';\nimport { RequestMetadata, ServiceExtension } from './ServiceExtension';\nimport type { SQS } from 'aws-sdk';\nimport {\n AwsSdkInstrumentationConfig,\n NormalizedRequest,\n NormalizedResponse,\n} from '../types';\nimport {\n MessagingDestinationKindValues,\n MessagingOperationValues,\n SemanticAttributes,\n} from '@opentelemetry/semantic-conventions';\nimport {\n contextGetter,\n extractPropagationContext,\n injectPropagationContext,\n addPropagationFieldsToAttributeNames,\n} from './MessageAttributes';\n\nexport class SqsServiceExtension implements ServiceExtension {\n requestPreSpanHook(request: NormalizedRequest): RequestMetadata {\n const queueUrl = this.extractQueueUrl(request.commandInput);\n const queueName = this.extractQueueNameFromUrl(queueUrl);\n let spanKind: SpanKind = SpanKind.CLIENT;\n let spanName: string | undefined;\n\n const spanAttributes = {\n [SemanticAttributes.MESSAGING_SYSTEM]: 'aws.sqs',\n [SemanticAttributes.MESSAGING_DESTINATION_KIND]:\n MessagingDestinationKindValues.QUEUE,\n [SemanticAttributes.MESSAGING_DESTINATION]: queueName,\n [SemanticAttributes.MESSAGING_URL]: queueUrl,\n };\n\n let isIncoming = false;\n\n switch (request.commandName) {\n case 'ReceiveMessage':\n {\n isIncoming = true;\n spanKind = SpanKind.CONSUMER;\n spanName = `${queueName} receive`;\n spanAttributes[SemanticAttributes.MESSAGING_OPERATION] =\n MessagingOperationValues.RECEIVE;\n\n request.commandInput.MessageAttributeNames =\n addPropagationFieldsToAttributeNames(\n request.commandInput.MessageAttributeNames,\n propagation.fields()\n );\n }\n break;\n\n case 'SendMessage':\n case 'SendMessageBatch':\n spanKind = SpanKind.PRODUCER;\n spanName = `${queueName} send`;\n break;\n }\n\n return {\n isIncoming,\n spanAttributes,\n spanKind,\n spanName,\n };\n }\n\n requestPostSpanHook = (request: NormalizedRequest) => {\n switch (request.commandName) {\n case 'SendMessage':\n {\n const origMessageAttributes =\n request.commandInput['MessageAttributes'] ?? {};\n if (origMessageAttributes) {\n request.commandInput['MessageAttributes'] =\n injectPropagationContext(origMessageAttributes);\n }\n }\n break;\n\n case 'SendMessageBatch':\n {\n request.commandInput?.Entries?.forEach(\n (messageParams: SQS.SendMessageBatchRequestEntry) => {\n messageParams.MessageAttributes = injectPropagationContext(\n messageParams.MessageAttributes ?? {}\n );\n }\n );\n }\n break;\n }\n };\n\n responseHook = (\n response: NormalizedResponse,\n span: Span,\n tracer: Tracer,\n config: AwsSdkInstrumentationConfig\n ) => {\n switch (response.request.commandName) {\n case 'SendMessage':\n span.setAttribute(\n SemanticAttributes.MESSAGING_MESSAGE_ID,\n response?.data?.MessageId\n );\n break;\n\n case 'SendMessageBatch':\n // TODO: How should this be handled?\n break;\n\n case 'ReceiveMessage': {\n const messages: SQS.Message[] = response?.data?.Messages;\n if (messages) {\n const queueUrl = this.extractQueueUrl(response.request.commandInput);\n const queueName = this.extractQueueNameFromUrl(queueUrl);\n\n pubsubPropagation.patchMessagesArrayToStartProcessSpans<SQS.Message>({\n messages,\n parentContext: trace.setSpan(context.active(), span),\n tracer,\n messageToSpanDetails: (message: SQS.Message) => ({\n name: queueName ?? 'unknown',\n parentContext: propagation.extract(\n ROOT_CONTEXT,\n extractPropagationContext(\n message,\n config.sqsExtractContextPropagationFromPayload\n ),\n contextGetter\n ),\n attributes: {\n [SemanticAttributes.MESSAGING_SYSTEM]: 'aws.sqs',\n [SemanticAttributes.MESSAGING_DESTINATION]: queueName,\n [SemanticAttributes.MESSAGING_DESTINATION_KIND]:\n MessagingDestinationKindValues.QUEUE,\n [SemanticAttributes.MESSAGING_MESSAGE_ID]: message.MessageId,\n [SemanticAttributes.MESSAGING_URL]: queueUrl,\n [SemanticAttributes.MESSAGING_OPERATION]:\n MessagingOperationValues.PROCESS,\n },\n }),\n processHook: (span: Span, message: SQS.Message) =>\n config.sqsProcessHook?.(span, { message }),\n });\n\n pubsubPropagation.patchArrayForProcessSpans(\n messages,\n tracer,\n context.active()\n );\n }\n break;\n }\n }\n };\n\n extractQueueUrl = (commandInput: Record<string, any>): string => {\n return commandInput?.QueueUrl;\n };\n\n extractQueueNameFromUrl = (queueUrl: string): string | undefined => {\n if (!queueUrl) return undefined;\n\n const segments = queueUrl.split('/');\n if (segments.length === 0) return undefined;\n\n return segments[segments.length - 1];\n };\n}\n"]}
1
+ {"version":3,"file":"sqs.js","sourceRoot":"","sources":["../../../src/services/sqs.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,4CAQ4B;AAC5B,wEAAqE;AAQrE,8EAI6C;AAC7C,2DAK6B;AAE7B,MAAa,mBAAmB;IAAhC;QAoDE,wBAAmB,GAAG,CAAC,OAA0B,EAAE,EAAE;;YACnD,QAAQ,OAAO,CAAC,WAAW,EAAE;gBAC3B,KAAK,aAAa;oBAChB;wBACE,MAAM,qBAAqB,GACzB,MAAA,OAAO,CAAC,YAAY,CAAC,mBAAmB,CAAC,mCAAI,EAAE,CAAC;wBAClD,IAAI,qBAAqB,EAAE;4BACzB,OAAO,CAAC,YAAY,CAAC,mBAAmB,CAAC;gCACvC,IAAA,4CAAwB,EAAC,qBAAqB,CAAC,CAAC;yBACnD;qBACF;oBACD,MAAM;gBAER,KAAK,kBAAkB;oBACrB;wBACE,MAAA,MAAA,OAAO,CAAC,YAAY,0CAAE,OAAO,0CAAE,OAAO,CACpC,CAAC,aAA+C,EAAE,EAAE;;4BAClD,aAAa,CAAC,iBAAiB,GAAG,IAAA,4CAAwB,EACxD,MAAA,aAAa,CAAC,iBAAiB,mCAAI,EAAE,CACtC,CAAC;wB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M,SAAS,GAAG,IAAI,CAAC,uBAAuB,CAAC,QAAQ,CAAC,CAAC;QACzD,IAAI,QAAQ,GAAa,cAAQ,CAAC,MAAM,CAAC;QACzC,IAAI,QAA4B,CAAC;QAEjC,MAAM,cAAc,GAAG;YACrB,CAAC,yCAAkB,CAAC,gBAAgB,CAAC,EAAE,SAAS;YAChD,CAAC,yCAAkB,CAAC,0BAA0B,CAAC,EAC7C,qDAA8B,CAAC,KAAK;YACtC,CAAC,yCAAkB,CAAC,qBAAqB,CAAC,EAAE,SAAS;YACrD,CAAC,yCAAkB,CAAC,aAAa,CAAC,EAAE,QAAQ;SAC7C,CAAC;QAEF,IAAI,UAAU,GAAG,KAAK,CAAC;QAEvB,QAAQ,OAAO,CAAC,WAAW,EAAE;YAC3B,KAAK,gBAAgB;gBACnB;oBACE,UAAU,GAAG,IAAI,CAAC;oBAClB,QAAQ,GAAG,cAAQ,CAAC,QAAQ,CAAC;oBAC7B,QAAQ,GAAG,GAAG,SAAS,UAAU,CAAC;oBAClC,cAAc,CAAC,yCAAkB,CAAC,mBAAmB,CAAC;wBACpD,+CAAwB,CAAC,OAAO,CAAC;oBAEnC,OAAO,CAAC,YAAY,CAAC,qBAAqB;wBACxC,IAAA,wDAAoC,EAClC,OAAO,CAAC,YAAY,CAAC,qBAAqB,EAC1C,iBAAW,CAAC,MAAM,EAAE,CACrB,CAAC;iBACL;gBACD,MAAM;YAER,KAAK,aAAa,CAAC;YACnB,KAAK,kBAAkB;gBACrB,QAAQ,GAAG,cAAQ,CAAC,QAAQ,CAAC;gBAC7B,QAAQ,GAAG,GAAG,SAAS,OAAO,CAAC;gBAC/B,MAAM;SACT;QAED,OAAO;YACL,UAAU;YACV,cAAc;YACd,QAAQ;YACR,QAAQ;SACT,CAAC;IACJ,CAAC;CAyGF;AA3JD,kDA2JC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n Tracer,\n SpanKind,\n Span,\n propagation,\n trace,\n context,\n ROOT_CONTEXT,\n} from '@opentelemetry/api';\nimport { pubsubPropagation } from '@opentelemetry/propagation-utils';\nimport { RequestMetadata, ServiceExtension } from './ServiceExtension';\nimport type { SQS } from 'aws-sdk';\nimport {\n AwsSdkInstrumentationConfig,\n NormalizedRequest,\n NormalizedResponse,\n} from '../types';\nimport {\n MessagingDestinationKindValues,\n MessagingOperationValues,\n SemanticAttributes,\n} from '@opentelemetry/semantic-conventions';\nimport {\n contextGetter,\n extractPropagationContext,\n injectPropagationContext,\n addPropagationFieldsToAttributeNames,\n} from './MessageAttributes';\n\nexport class SqsServiceExtension implements ServiceExtension {\n requestPreSpanHook(\n request: NormalizedRequest,\n _config: AwsSdkInstrumentationConfig\n ): RequestMetadata {\n const queueUrl = this.extractQueueUrl(request.commandInput);\n const queueName = this.extractQueueNameFromUrl(queueUrl);\n let spanKind: SpanKind = SpanKind.CLIENT;\n let spanName: string | undefined;\n\n const spanAttributes = {\n [SemanticAttributes.MESSAGING_SYSTEM]: 'aws.sqs',\n [SemanticAttributes.MESSAGING_DESTINATION_KIND]:\n MessagingDestinationKindValues.QUEUE,\n [SemanticAttributes.MESSAGING_DESTINATION]: queueName,\n [SemanticAttributes.MESSAGING_URL]: queueUrl,\n };\n\n let isIncoming = false;\n\n switch (request.commandName) {\n case 'ReceiveMessage':\n {\n isIncoming = true;\n spanKind = SpanKind.CONSUMER;\n spanName = `${queueName} receive`;\n spanAttributes[SemanticAttributes.MESSAGING_OPERATION] =\n MessagingOperationValues.RECEIVE;\n\n request.commandInput.MessageAttributeNames =\n addPropagationFieldsToAttributeNames(\n request.commandInput.MessageAttributeNames,\n propagation.fields()\n );\n }\n break;\n\n case 'SendMessage':\n case 'SendMessageBatch':\n spanKind = SpanKind.PRODUCER;\n spanName = `${queueName} send`;\n break;\n }\n\n return {\n isIncoming,\n spanAttributes,\n spanKind,\n spanName,\n };\n }\n\n requestPostSpanHook = (request: NormalizedRequest) => {\n switch (request.commandName) {\n case 'SendMessage':\n {\n const origMessageAttributes =\n request.commandInput['MessageAttributes'] ?? {};\n if (origMessageAttributes) {\n request.commandInput['MessageAttributes'] =\n injectPropagationContext(origMessageAttributes);\n }\n }\n break;\n\n case 'SendMessageBatch':\n {\n request.commandInput?.Entries?.forEach(\n (messageParams: SQS.SendMessageBatchRequestEntry) => {\n messageParams.MessageAttributes = injectPropagationContext(\n messageParams.MessageAttributes ?? {}\n );\n }\n );\n }\n break;\n }\n };\n\n responseHook = (\n response: NormalizedResponse,\n span: Span,\n tracer: Tracer,\n config: AwsSdkInstrumentationConfig\n ) => {\n switch (response.request.commandName) {\n case 'SendMessage':\n span.setAttribute(\n SemanticAttributes.MESSAGING_MESSAGE_ID,\n response?.data?.MessageId\n );\n break;\n\n case 'SendMessageBatch':\n // TODO: How should this be handled?\n break;\n\n case 'ReceiveMessage': {\n const messages: SQS.Message[] = response?.data?.Messages;\n if (messages) {\n const queueUrl = this.extractQueueUrl(response.request.commandInput);\n const queueName = this.extractQueueNameFromUrl(queueUrl);\n\n pubsubPropagation.patchMessagesArrayToStartProcessSpans<SQS.Message>({\n messages,\n parentContext: trace.setSpan(context.active(), span),\n tracer,\n messageToSpanDetails: (message: SQS.Message) => ({\n name: queueName ?? 'unknown',\n parentContext: propagation.extract(\n ROOT_CONTEXT,\n extractPropagationContext(\n message,\n config.sqsExtractContextPropagationFromPayload\n ),\n contextGetter\n ),\n attributes: {\n [SemanticAttributes.MESSAGING_SYSTEM]: 'aws.sqs',\n [SemanticAttributes.MESSAGING_DESTINATION]: queueName,\n [SemanticAttributes.MESSAGING_DESTINATION_KIND]:\n MessagingDestinationKindValues.QUEUE,\n [SemanticAttributes.MESSAGING_MESSAGE_ID]: message.MessageId,\n [SemanticAttributes.MESSAGING_URL]: queueUrl,\n [SemanticAttributes.MESSAGING_OPERATION]:\n MessagingOperationValues.PROCESS,\n },\n }),\n processHook: (span: Span, message: SQS.Message) =>\n config.sqsProcessHook?.(span, { message }),\n });\n\n pubsubPropagation.patchArrayForProcessSpans(\n messages,\n tracer,\n context.active()\n );\n }\n break;\n }\n }\n };\n\n extractQueueUrl = (commandInput: Record<string, any>): string => {\n return commandInput?.QueueUrl;\n };\n\n extractQueueNameFromUrl = (queueUrl: string): string | undefined => {\n if (!queueUrl) return undefined;\n\n const segments = queueUrl.split('/');\n if (segments.length === 0) return undefined;\n\n return segments[segments.length - 1];\n };\n}\n"]}
@@ -1,6 +1,7 @@
1
1
  import { Span } from '@opentelemetry/api';
2
2
  import { InstrumentationConfig } from '@opentelemetry/instrumentation';
3
3
  import { SQS } from './aws-sdk.types';
4
+ export declare type CommandInput = Record<string, any>;
4
5
  /**
5
6
  * These are normalized request and response, which are used by both sdk v2 and v3.
6
7
  * They organize the relevant data in one interface which can be processed in a
@@ -9,7 +10,7 @@ import { SQS } from './aws-sdk.types';
9
10
  export interface NormalizedRequest {
10
11
  serviceName: string;
11
12
  commandName: string;
12
- commandInput: Record<string, any>;
13
+ commandInput: CommandInput;
13
14
  region?: string;
14
15
  }
15
16
  export interface NormalizedResponse {
@@ -42,6 +43,7 @@ export interface AwsSdkSqsProcessHookInformation {
42
43
  export interface AwsSdkSqsProcessCustomAttributeFunction {
43
44
  (span: Span, sqsProcessInfo: AwsSdkSqsProcessHookInformation): void;
44
45
  }
46
+ export declare type AwsSdkDynamoDBStatementSerializer = (operation: string, commandInput: CommandInput) => string | undefined;
45
47
  export interface AwsSdkInstrumentationConfig extends InstrumentationConfig {
46
48
  /** hook for adding custom attributes before request is sent to aws */
47
49
  preRequestHook?: AwsSdkRequestCustomAttributeFunction;
@@ -49,6 +51,8 @@ export interface AwsSdkInstrumentationConfig extends InstrumentationConfig {
49
51
  responseHook?: AwsSdkResponseCustomAttributeFunction;
50
52
  /** hook for adding custom attribute when an sqs process span is started */
51
53
  sqsProcessHook?: AwsSdkSqsProcessCustomAttributeFunction;
54
+ /** custom serializer function for the db.statement attribute in DynamoDB spans */
55
+ dynamoDBStatementSerializer?: AwsSdkDynamoDBStatementSerializer;
52
56
  /**
53
57
  * Most aws operation use http request under the hood.
54
58
  * if http instrumentation is enabled, each aws operation will also create
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { Span } from '@opentelemetry/api';\nimport { InstrumentationConfig } from '@opentelemetry/instrumentation';\nimport { SQS } from './aws-sdk.types';\n\n/**\n * These are normalized request and response, which are used by both sdk v2 and v3.\n * They organize the relevant data in one interface which can be processed in a\n * uniform manner in hooks\n */\nexport interface NormalizedRequest {\n serviceName: string;\n commandName: string;\n commandInput: Record<string, any>;\n region?: string;\n}\nexport interface NormalizedResponse {\n data: any;\n request: NormalizedRequest;\n requestId: string;\n}\n\nexport interface AwsSdkRequestHookInformation {\n moduleVersion?: string;\n request: NormalizedRequest;\n}\nexport interface AwsSdkRequestCustomAttributeFunction {\n (span: Span, requestInfo: AwsSdkRequestHookInformation): void;\n}\n\nexport interface AwsSdkResponseHookInformation {\n moduleVersion?: string;\n response: NormalizedResponse;\n}\n/**\n * span can be used to add custom attributes, or for any other need.\n * response is the object that is returned to the user calling the aws-sdk operation.\n * The response type and attributes on the response are client-specific.\n */\nexport interface AwsSdkResponseCustomAttributeFunction {\n (span: Span, responseInfo: AwsSdkResponseHookInformation): void;\n}\n\nexport interface AwsSdkSqsProcessHookInformation {\n message: SQS.Message;\n}\nexport interface AwsSdkSqsProcessCustomAttributeFunction {\n (span: Span, sqsProcessInfo: AwsSdkSqsProcessHookInformation): void;\n}\n\nexport interface AwsSdkInstrumentationConfig extends InstrumentationConfig {\n /** hook for adding custom attributes before request is sent to aws */\n preRequestHook?: AwsSdkRequestCustomAttributeFunction;\n\n /** hook for adding custom attributes when response is received from aws */\n responseHook?: AwsSdkResponseCustomAttributeFunction;\n\n /** hook for adding custom attribute when an sqs process span is started */\n sqsProcessHook?: AwsSdkSqsProcessCustomAttributeFunction;\n\n /**\n * Most aws operation use http request under the hood.\n * if http instrumentation is enabled, each aws operation will also create\n * an http/s child describing the communication with amazon servers.\n * Setting the `suppressInternalInstrumentation` config value to `true` will\n * cause the instrumentation to suppress instrumentation of underlying operations,\n * effectively causing those http spans to be non-recordable.\n */\n suppressInternalInstrumentation?: boolean;\n\n /**\n * In some cases the context propagation headers may be found in the message payload\n * rather than the message attribute.\n * When this field is turned on the instrumentation will parse the payload and extract the\n * context from there.\n * Even if the field is on and MessageAttribute contains context propagation field are present,\n * the MessageAttribute will get priority.\n * By default it is off.\n */\n sqsExtractContextPropagationFromPayload?: boolean;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { Span } from '@opentelemetry/api';\nimport { InstrumentationConfig } from '@opentelemetry/instrumentation';\nimport { SQS } from './aws-sdk.types';\n\nexport type CommandInput = Record<string, any>;\n\n/**\n * These are normalized request and response, which are used by both sdk v2 and v3.\n * They organize the relevant data in one interface which can be processed in a\n * uniform manner in hooks\n */\nexport interface NormalizedRequest {\n serviceName: string;\n commandName: string;\n commandInput: CommandInput;\n region?: string;\n}\nexport interface NormalizedResponse {\n data: any;\n request: NormalizedRequest;\n requestId: string;\n}\n\nexport interface AwsSdkRequestHookInformation {\n moduleVersion?: string;\n request: NormalizedRequest;\n}\nexport interface AwsSdkRequestCustomAttributeFunction {\n (span: Span, requestInfo: AwsSdkRequestHookInformation): void;\n}\n\nexport interface AwsSdkResponseHookInformation {\n moduleVersion?: string;\n response: NormalizedResponse;\n}\n/**\n * span can be used to add custom attributes, or for any other need.\n * response is the object that is returned to the user calling the aws-sdk operation.\n * The response type and attributes on the response are client-specific.\n */\nexport interface AwsSdkResponseCustomAttributeFunction {\n (span: Span, responseInfo: AwsSdkResponseHookInformation): void;\n}\n\nexport interface AwsSdkSqsProcessHookInformation {\n message: SQS.Message;\n}\nexport interface AwsSdkSqsProcessCustomAttributeFunction {\n (span: Span, sqsProcessInfo: AwsSdkSqsProcessHookInformation): void;\n}\n\nexport type AwsSdkDynamoDBStatementSerializer = (\n operation: string,\n commandInput: CommandInput\n) => string | undefined;\n\nexport interface AwsSdkInstrumentationConfig extends InstrumentationConfig {\n /** hook for adding custom attributes before request is sent to aws */\n preRequestHook?: AwsSdkRequestCustomAttributeFunction;\n\n /** hook for adding custom attributes when response is received from aws */\n responseHook?: AwsSdkResponseCustomAttributeFunction;\n\n /** hook for adding custom attribute when an sqs process span is started */\n sqsProcessHook?: AwsSdkSqsProcessCustomAttributeFunction;\n\n /** custom serializer function for the db.statement attribute in DynamoDB spans */\n dynamoDBStatementSerializer?: AwsSdkDynamoDBStatementSerializer;\n\n /**\n * Most aws operation use http request under the hood.\n * if http instrumentation is enabled, each aws operation will also create\n * an http/s child describing the communication with amazon servers.\n * Setting the `suppressInternalInstrumentation` config value to `true` will\n * cause the instrumentation to suppress instrumentation of underlying operations,\n * effectively causing those http spans to be non-recordable.\n */\n suppressInternalInstrumentation?: boolean;\n\n /**\n * In some cases the context propagation headers may be found in the message payload\n * rather than the message attribute.\n * When this field is turned on the instrumentation will parse the payload and extract the\n * context from there.\n * Even if the field is on and MessageAttribute contains context propagation field are present,\n * the MessageAttribute will get priority.\n * By default it is off.\n */\n sqsExtractContextPropagationFromPayload?: boolean;\n}\n"]}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.36.2";
1
+ export declare const VERSION = "0.37.1";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -17,5 +17,5 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.VERSION = void 0;
19
19
  // this is autogenerated file, see scripts/version-update.js
20
- exports.VERSION = '0.36.2';
20
+ exports.VERSION = '0.37.1';
21
21
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.36.2';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '0.37.1';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentelemetry/instrumentation-aws-sdk",
3
- "version": "0.36.2",
3
+ "version": "0.37.1",
4
4
  "description": "OpenTelemetry automatic instrumentation for the `aws-sdk` package",
5
5
  "keywords": [
6
6
  "aws",
@@ -33,7 +33,7 @@
33
33
  "lint:fix": "eslint . --ext .ts --fix",
34
34
  "precompile": "tsc --version && lerna run version:update --scope @opentelemetry/instrumentation-aws-sdk --include-dependencies",
35
35
  "prewatch": "npm run precompile",
36
- "prepare": "npm run compile",
36
+ "prepublishOnly": "npm run compile",
37
37
  "tdd": "npm run test -- --watch-extensions ts --watch",
38
38
  "test": "nyc ts-mocha -p tsconfig.json --require '@opentelemetry/contrib-test-utils' 'test/**/*.test.ts'",
39
39
  "test-all-versions": "tav",
@@ -46,7 +46,7 @@
46
46
  "dependencies": {
47
47
  "@opentelemetry/core": "^1.8.0",
48
48
  "@opentelemetry/instrumentation": "^0.45.1",
49
- "@opentelemetry/propagation-utils": "^0.30.3",
49
+ "@opentelemetry/propagation-utils": "^0.30.4",
50
50
  "@opentelemetry/semantic-conventions": "^1.0.0"
51
51
  },
52
52
  "devDependencies": {
@@ -57,7 +57,7 @@
57
57
  "@aws-sdk/client-sqs": "3.85.0",
58
58
  "@aws-sdk/types": "3.78.0",
59
59
  "@opentelemetry/api": "^1.3.0",
60
- "@opentelemetry/contrib-test-utils": "^0.34.3",
60
+ "@opentelemetry/contrib-test-utils": "^0.35.0",
61
61
  "@opentelemetry/sdk-trace-base": "^1.8.0",
62
62
  "@types/mocha": "8.2.3",
63
63
  "@types/node": "18.6.5",
@@ -77,5 +77,5 @@
77
77
  "engines": {
78
78
  "node": ">=14"
79
79
  },
80
- "gitHead": "607d375595da3ab51b7f773ac360900121c4361b"
80
+ "gitHead": "c7e7000b7bf79b0b107c448b403c2613a9b9e2c1"
81
81
  }