@opentelemetry/instrumentation-aws-sdk 0.56.0 → 0.57.0

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
@@ -52,6 +52,7 @@ aws-sdk instrumentation has few options available to choose from. You can set th
52
52
  | ----------------------------------------- | ----------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
53
53
  | `preRequestHook` | `AwsSdkRequestCustomAttributeFunction` | Hook called before request send, which allow to add custom attributes to span. |
54
54
  | `responseHook` | `AwsSdkResponseCustomAttributeFunction` | Hook for adding custom attributes when response is received from aws. |
55
+ | `exceptionHook` | `AwsSdkExceptionCustomAttributeFunction` | Hook for adding custom attributes when exception is received from aws. |
55
56
  | `sqsProcessHook` | `AwsSdkSqsProcessCustomAttributeFunction` | Hook called after starting sqs `process` span (for each sqs received message), which allow to add custom attributes to it. |
56
57
  | `suppressInternalInstrumentation` | `boolean` | Most aws operation use http requests under the hood. Set this to `true` to hide all underlying http spans. |
57
58
  | `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) |
@@ -12,6 +12,7 @@ export declare class AwsInstrumentation extends InstrumentationBase<AwsSdkInstru
12
12
  private _startAwsV3Span;
13
13
  private _callUserPreRequestHook;
14
14
  private _callUserResponseHook;
15
+ private _callUserExceptionResponseHook;
15
16
  private _getV3ConstructStackPatch;
16
17
  private _getV3SmithyClientSendPatch;
17
18
  private patchV3MiddlewareStack;
@@ -113,6 +113,18 @@ class AwsInstrumentation extends instrumentation_1.InstrumentationBase {
113
113
  api_1.diag.error(`${AwsInstrumentation.component} instrumentation: responseHook error`, e);
114
114
  }, true);
115
115
  }
116
+ _callUserExceptionResponseHook(span, request, err) {
117
+ const { exceptionHook } = this.getConfig();
118
+ if (!exceptionHook)
119
+ return;
120
+ const requestInfo = {
121
+ request,
122
+ };
123
+ (0, instrumentation_1.safeExecuteInTheMiddle)(() => exceptionHook(span, requestInfo, err), (e) => {
124
+ if (e)
125
+ api_1.diag.error(`${AwsInstrumentation.component} instrumentation: exceptionHook error`, e);
126
+ }, true);
127
+ }
116
128
  _getV3ConstructStackPatch(moduleVersion, original) {
117
129
  const self = this;
118
130
  return function constructStack(...args) {
@@ -224,6 +236,7 @@ class AwsInstrumentation extends instrumentation_1.InstrumentationBase {
224
236
  message: err.message,
225
237
  });
226
238
  span.recordException(err);
239
+ self._callUserExceptionResponseHook(span, normalizedRequest, err);
227
240
  throw err;
228
241
  })
229
242
  .finally(() => {
@@ -1 +1 @@
1
- {"version":3,"file":"aws-sdk.js","sourceRoot":"","sources":["../../src/aws-sdk.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,4CAO4B;AAC5B,8CAA8D;AAC9D,mCAAyC;AACzC,yCAAgD;AAQhD,kBAAkB;AAClB,uCAA0D;AAC1D,oEAOwC;AAQxC,mCAKiB;AACjB,yCAAsC;AAEtC,8EAAgF;AAEhF,MAAM,oBAAoB,GAAG,MAAM,CACjC,qDAAqD,CACtD,CAAC;AAKF,MAAa,kBAAmB,SAAQ,qCAAgD;IACtF,MAAM,CAAU,SAAS,GAAG,SAAS,CAAC;IAItC,YAAY,SAAsC,EAAE;QAClD,KAAK,CAAC,sBAAY,EAAE,yBAAe,EAAE,MAAM,CAAC,CAAC;IAC/C,CAAC;IAES,IAAI;QACZ,MAAM,gCAAgC,GAAG,IAAI,+CAA6B,CACxE,uDAAuD,EACvD,CAAC,iBAAiB,CAAC,EACnB,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,EACrC,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,IAAI,CAAC,CACxC,CAAC;QACF,MAAM,gCAAgC,GAAG,IAAI,+CAA6B,CACxE,uDAAuD,EACvD,CAAC,UAAU,CAAC,EACZ,IAAI,CAAC,qBAAqB,CAAC,IAAI,CAAC,IAAI,CAAC,EACr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CAAC;6BACD,OAAO,CAAC,GAAG,EAAE;4BACZ,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE;gCAC7B,IAAI,CAAC,GAAG,EAAE,CAAC;6BACZ;wBACH,CAAC,CAAC,CAAC;wBACL,wBAAwB;6BACrB,IAAI,CAAC,GAAG,CAAC,EAAE;4BACV,OAAO,CAAC,GAAG,CAAC,CAAC;wBACf,CAAC,CAAC;6BACD,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;oBAC/B,CAAC,CAAC,CAAC;gBACP,CAAC,CAAC,CAAC;gBAEH,OAAO,eAAe,CAAC,UAAU;oBAC/B,CAAC,CAAC,IAAA,mBAAW,EAAC,cAAc,EAAE,qBAAqB,EAAE,CAAC,CAAC;oBACvD,CAAC,CAAC,cAAc,CAAC;YACrB,CAAC,CAAC;YACF,OAAO,cAAc,CAAC;QACxB,CAAC,CAAC;IACJ,CAAC;IAEO,qBAAqB,CAAI,gBAAuC;QACtE,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC,+BAA+B,EAAE;YACpD,OAAO,aAAO,CAAC,IAAI,CAAC,IAAA,sBAAe,EAAC,aAAO,CAAC,MAAM,EAAE,CAAC,EAAE,gBAAgB,CAAC,CAAC;SAC1E;aAAM;YACL,OAAO,gBAAgB,EAAE,CAAC;SAC3B;IACH,CAAC;IAEQ,wBAAwB;QAC/B,IAAI,CAAC,IAAI,CAAC,kBAAkB,EAAE;YAC5B,IAAI,CAAC,kBAAkB,GAAG,IAAI,6BAAkB,EAAE,CAAC;SACpD;QACD,IAAI,CAAC,kBAAkB,CAAC,uBAAuB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC9D,CAAC;;AA9ZU,gDAAkB","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 diag,\n SpanStatusCode,\n} from '@opentelemetry/api';\nimport { hrTime, suppressTracing } from '@opentelemetry/core';\nimport { AttributeNames } from './enums';\nimport { ServicesExtensions } from './services';\nimport {\n AwsSdkInstrumentationConfig,\n AwsSdkRequestHookInformation,\n AwsSdkResponseHookInformation,\n NormalizedRequest,\n NormalizedResponse,\n} from './types';\n/** @knipignore */\nimport { PACKAGE_NAME, PACKAGE_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 normalizeV3Request,\n removeSuffixFromStringIfExists,\n} from './utils';\nimport { propwrap } from './propwrap';\nimport { RequestMetadata } from './services/ServiceExtension';\nimport { SEMATTRS_HTTP_STATUS_CODE } 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\nexport class AwsInstrumentation extends InstrumentationBase<AwsSdkInstrumentationConfig> {\n static readonly component = 'aws-sdk';\n // need declare since initialized in callbacks from super constructor\n private declare servicesExtensions: ServicesExtensions;\n\n constructor(config: AwsSdkInstrumentationConfig = {}) {\n super(PACKAGE_NAME, PACKAGE_VERSION, config);\n }\n\n protected init(): InstrumentationModuleDefinition[] {\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 '@aws-sdk/middleware-stack',\n ['^3.1.0'],\n undefined,\n undefined,\n [v3MiddlewareStackFileOldVersions, v3MiddlewareStackFileNewVersions]\n );\n\n // Patch for @smithy/middleware-stack for @aws-sdk/* packages v3.363.0+.\n // As of @smithy/middleware-stack@2.1.0 `constructStack` is only available\n // as a getter, so we cannot use `this._wrap()`.\n const self = this;\n const v3SmithyMiddlewareStack = new InstrumentationNodeModuleDefinition(\n '@smithy/middleware-stack',\n ['>=2.0.0'],\n (moduleExports, moduleVersion) => {\n const newExports = propwrap(\n moduleExports,\n 'constructStack',\n (orig: any) => {\n self._diag.debug('propwrapping aws-sdk v3 constructStack');\n return self._getV3ConstructStackPatch(moduleVersion, orig);\n }\n );\n return newExports;\n }\n );\n\n const v3SmithyClient = new InstrumentationNodeModuleDefinition(\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 return [\n v3MiddlewareStack,\n v3SmithyMiddlewareStack,\n v3SmithyClient,\n v3NewSmithyClient,\n ];\n }\n\n protected patchV3ConstructStack(moduleExports: any, moduleVersion?: string) {\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 this._unwrap(moduleExports, 'constructStack');\n return moduleExports;\n }\n\n protected patchV3SmithyClient(moduleExports: any) {\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 this._unwrap(moduleExports.Client.prototype, 'send');\n return moduleExports;\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 _callUserPreRequestHook(\n span: Span,\n request: NormalizedRequest,\n moduleVersion: string | undefined\n ) {\n const { preRequestHook } = this.getConfig();\n if (preRequestHook) {\n const requestInfo: AwsSdkRequestHookInformation = {\n moduleVersion,\n request,\n };\n safeExecuteInTheMiddle(\n () => 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.getConfig();\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 _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 // Use 'AWS' as a fallback serviceName to match type definition.\n // In practice, `clientName` should always be set.\n awsExecutionContext.clientName || 'AWS',\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.getConfig(),\n self._diag\n );\n const startTime = hrTime();\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.CLOUD_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 SEMATTRS_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 const override = self.servicesExtensions.responseHook(\n normalizedResponse,\n span,\n self.tracer,\n self.getConfig(),\n startTime\n );\n if (override) {\n response.output = override;\n normalizedResponse.data = override;\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\n const httpStatusCode = err?.$metadata?.httpStatusCode;\n if (httpStatusCode) {\n span.setAttribute(\n SEMATTRS_HTTP_STATUS_CODE,\n httpStatusCode\n );\n }\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 if (!requestMetadata.isStream) {\n span.end();\n }\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 _callOriginalFunction<T>(originalFunction: (...args: any[]) => T): T {\n if (this.getConfig().suppressInternalInstrumentation) {\n return context.with(suppressTracing(context.active()), originalFunction);\n } else {\n return originalFunction();\n }\n }\n\n override _updateMetricInstruments() {\n if (!this.servicesExtensions) {\n this.servicesExtensions = new ServicesExtensions();\n }\n this.servicesExtensions.updateMetricInstruments(this.meter);\n }\n}\n"]}
1
+ {"version":3,"file":"aws-sdk.js","sourceRoot":"","sources":["../../src/aws-sdk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penTelemetry 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 diag,\n SpanStatusCode,\n} from '@opentelemetry/api';\nimport { hrTime, suppressTracing } from '@opentelemetry/core';\nimport { AttributeNames } from './enums';\nimport { ServicesExtensions } from './services';\nimport {\n AwsSdkInstrumentationConfig,\n AwsSdkRequestHookInformation,\n AwsSdkResponseHookInformation,\n NormalizedRequest,\n NormalizedResponse,\n} from './types';\n/** @knipignore */\nimport { PACKAGE_NAME, PACKAGE_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 normalizeV3Request,\n removeSuffixFromStringIfExists,\n} from './utils';\nimport { propwrap } from './propwrap';\nimport { RequestMetadata } from './services/ServiceExtension';\nimport { SEMATTRS_HTTP_STATUS_CODE } 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\nexport class AwsInstrumentation extends InstrumentationBase<AwsSdkInstrumentationConfig> {\n static readonly component = 'aws-sdk';\n // need declare since initialized in callbacks from super constructor\n private declare servicesExtensions: ServicesExtensions;\n\n constructor(config: AwsSdkInstrumentationConfig = {}) {\n super(PACKAGE_NAME, PACKAGE_VERSION, config);\n }\n\n protected init(): InstrumentationModuleDefinition[] {\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 '@aws-sdk/middleware-stack',\n ['^3.1.0'],\n undefined,\n undefined,\n [v3MiddlewareStackFileOldVersions, v3MiddlewareStackFileNewVersions]\n );\n\n // Patch for @smithy/middleware-stack for @aws-sdk/* packages v3.363.0+.\n // As of @smithy/middleware-stack@2.1.0 `constructStack` is only available\n // as a getter, so we cannot use `this._wrap()`.\n const self = this;\n const v3SmithyMiddlewareStack = new InstrumentationNodeModuleDefinition(\n '@smithy/middleware-stack',\n ['>=2.0.0'],\n (moduleExports, moduleVersion) => {\n const newExports = propwrap(\n moduleExports,\n 'constructStack',\n (orig: any) => {\n self._diag.debug('propwrapping aws-sdk v3 constructStack');\n return self._getV3ConstructStackPatch(moduleVersion, orig);\n }\n );\n return newExports;\n }\n );\n\n const v3SmithyClient = new InstrumentationNodeModuleDefinition(\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 return [\n v3MiddlewareStack,\n v3SmithyMiddlewareStack,\n v3SmithyClient,\n v3NewSmithyClient,\n ];\n }\n\n protected patchV3ConstructStack(moduleExports: any, moduleVersion?: string) {\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 this._unwrap(moduleExports, 'constructStack');\n return moduleExports;\n }\n\n protected patchV3SmithyClient(moduleExports: any) {\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 this._unwrap(moduleExports.Client.prototype, 'send');\n return moduleExports;\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 _callUserPreRequestHook(\n span: Span,\n request: NormalizedRequest,\n moduleVersion: string | undefined\n ) {\n const { preRequestHook } = this.getConfig();\n if (preRequestHook) {\n const requestInfo: AwsSdkRequestHookInformation = {\n moduleVersion,\n request,\n };\n safeExecuteInTheMiddle(\n () => 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.getConfig();\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 _callUserExceptionResponseHook(\n span: Span,\n request: NormalizedRequest,\n err: any\n ) {\n const { exceptionHook } = this.getConfig();\n if (!exceptionHook) return;\n const requestInfo: AwsSdkRequestHookInformation = {\n request,\n };\n\n safeExecuteInTheMiddle(\n () => exceptionHook(span, requestInfo, err),\n (e: Error | undefined) => {\n if (e)\n diag.error(\n `${AwsInstrumentation.component} instrumentation: exceptionHook error`,\n e\n );\n },\n true\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 // Use 'AWS' as a fallback serviceName to match type definition.\n // In practice, `clientName` should always be set.\n awsExecutionContext.clientName || 'AWS',\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.getConfig(),\n self._diag\n );\n const startTime = hrTime();\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.CLOUD_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 SEMATTRS_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 const override = self.servicesExtensions.responseHook(\n normalizedResponse,\n span,\n self.tracer,\n self.getConfig(),\n startTime\n );\n if (override) {\n response.output = override;\n normalizedResponse.data = override;\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\n const httpStatusCode = err?.$metadata?.httpStatusCode;\n if (httpStatusCode) {\n span.setAttribute(\n SEMATTRS_HTTP_STATUS_CODE,\n httpStatusCode\n );\n }\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 self._callUserExceptionResponseHook(\n span,\n normalizedRequest,\n err\n );\n throw err;\n })\n .finally(() => {\n if (!requestMetadata.isStream) {\n span.end();\n }\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 _callOriginalFunction<T>(originalFunction: (...args: any[]) => T): T {\n if (this.getConfig().suppressInternalInstrumentation) {\n return context.with(suppressTracing(context.active()), originalFunction);\n } else {\n return originalFunction();\n }\n }\n\n override _updateMetricInstruments() {\n if (!this.servicesExtensions) {\n this.servicesExtensions = new ServicesExtensions();\n }\n this.servicesExtensions.updateMetricInstruments(this.meter);\n }\n}\n"]}
@@ -37,6 +37,13 @@ export interface AwsSdkResponseHookInformation {
37
37
  export interface AwsSdkResponseCustomAttributeFunction {
38
38
  (span: Span, responseInfo: AwsSdkResponseHookInformation): void;
39
39
  }
40
+ /**
41
+ * span can be used to modify the status.
42
+ * As we have no response object, the request can be used to determine the failed aws-sdk operation.
43
+ */
44
+ export interface AwsSdkExceptionCustomAttributeFunction {
45
+ (span: Span, requestInfo: AwsSdkRequestHookInformation, err: any): void;
46
+ }
40
47
  export interface AwsSdkSqsProcessHookInformation {
41
48
  message: SQS.Message;
42
49
  }
@@ -49,6 +56,11 @@ export interface AwsSdkInstrumentationConfig extends InstrumentationConfig {
49
56
  preRequestHook?: AwsSdkRequestCustomAttributeFunction;
50
57
  /** hook for adding custom attributes when response is received from aws */
51
58
  responseHook?: AwsSdkResponseCustomAttributeFunction;
59
+ /**
60
+ * Hook for adding custom attributes when exception is received from aws.
61
+ * This hook is only available with aws sdk v3
62
+ */
63
+ exceptionHook?: AwsSdkExceptionCustomAttributeFunction;
52
64
  /** hook for adding custom attribute when an sqs process span is started */
53
65
  sqsProcessHook?: AwsSdkSqsProcessCustomAttributeFunction;
54
66
  /** custom serializer function for the db.statement attribute in DynamoDB spans */
@@ -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\nexport type CommandInput = Record<string, any>;\n\n/**\n * These are normalized request and response.\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
+ {"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.\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/**\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\n/**\n * span can be used to modify the status.\n * As we have no response object, the request can be used to determine the failed aws-sdk operation.\n */\nexport interface AwsSdkExceptionCustomAttributeFunction {\n (span: Span, requestInfo: AwsSdkRequestHookInformation, err: any): 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 /**\n * Hook for adding custom attributes when exception is received from aws.\n * This hook is only available with aws sdk v3\n */\n exceptionHook?: AwsSdkExceptionCustomAttributeFunction;\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,3 +1,3 @@
1
- export declare const PACKAGE_VERSION = "0.56.0";
1
+ export declare const PACKAGE_VERSION = "0.57.0";
2
2
  export declare const PACKAGE_NAME = "@opentelemetry/instrumentation-aws-sdk";
3
3
  //# sourceMappingURL=version.d.ts.map
@@ -17,6 +17,6 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.PACKAGE_NAME = exports.PACKAGE_VERSION = void 0;
19
19
  // this is autogenerated file, see scripts/version-update.js
20
- exports.PACKAGE_VERSION = '0.56.0';
20
+ exports.PACKAGE_VERSION = '0.57.0';
21
21
  exports.PACKAGE_NAME = '@opentelemetry/instrumentation-aws-sdk';
22
22
  //# 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,eAAe,GAAG,QAAQ,CAAC;AAC3B,QAAA,YAAY,GAAG,wCAAwC,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 PACKAGE_VERSION = '0.56.0';\nexport const PACKAGE_NAME = '@opentelemetry/instrumentation-aws-sdk';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,eAAe,GAAG,QAAQ,CAAC;AAC3B,QAAA,YAAY,GAAG,wCAAwC,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 PACKAGE_VERSION = '0.57.0';\nexport const PACKAGE_NAME = '@opentelemetry/instrumentation-aws-sdk';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentelemetry/instrumentation-aws-sdk",
3
- "version": "0.56.0",
3
+ "version": "0.57.0",
4
4
  "description": "OpenTelemetry instrumentation for `aws-sdk` and `@aws-sdk/client-*` clients for various AWS services",
5
5
  "keywords": [
6
6
  "aws",
@@ -32,7 +32,7 @@
32
32
  },
33
33
  "scripts": {
34
34
  "clean": "rimraf build/*",
35
- "setup:dev": "nx run-many -t compile -p @opentelemetry/instrumentation-aws-sdk",
35
+ "compile:with-dependencies": "nx run-many -t compile -p @opentelemetry/instrumentation-aws-sdk",
36
36
  "compile": "tsc -p .",
37
37
  "lint": "eslint . --ext .ts",
38
38
  "lint:fix": "eslint . --ext .ts --fix",
@@ -65,7 +65,7 @@
65
65
  "@opentelemetry/api": "^1.3.0",
66
66
  "@opentelemetry/contrib-test-utils": "^0.49.0",
67
67
  "@opentelemetry/sdk-trace-base": "^2.0.0",
68
- "@smithy/node-http-handler": "2.4.0",
68
+ "@smithy/node-http-handler": "4.1.0",
69
69
  "@types/mocha": "10.0.10",
70
70
  "@types/node": "18.18.14",
71
71
  "@types/sinon": "17.0.4",
@@ -81,5 +81,5 @@
81
81
  "engines": {
82
82
  "node": "^18.19.0 || >=20.6.0"
83
83
  },
84
- "gitHead": "e7960a2061c0a039ffa57ed8dbb73d605d65f4f6"
84
+ "gitHead": "aca1437f8ce0315b3941460063311bb8332020b8"
85
85
  }