@opentelemetry/instrumentation-aws-sdk 0.52.0 → 0.53.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/build/src/aws-sdk.d.ts +1 -0
- package/build/src/aws-sdk.js +8 -2
- package/build/src/aws-sdk.js.map +1 -1
- package/build/src/semconv.d.ts +17 -0
- package/build/src/semconv.js +18 -1
- package/build/src/semconv.js.map +1 -1
- package/build/src/services/ServiceExtension.d.ts +3 -2
- package/build/src/services/ServiceExtension.js.map +1 -1
- package/build/src/services/ServicesExtensions.d.ts +3 -2
- package/build/src/services/ServicesExtensions.js +7 -2
- package/build/src/services/ServicesExtensions.js.map +1 -1
- package/build/src/services/bedrock-runtime.d.ts +5 -2
- package/build/src/services/bedrock-runtime.js +62 -3
- package/build/src/services/bedrock-runtime.js.map +1 -1
- package/build/src/version.d.ts +1 -1
- package/build/src/version.js +1 -1
- package/build/src/version.js.map +1 -1
- package/package.json +6 -6
package/build/src/aws-sdk.d.ts
CHANGED
|
@@ -18,5 +18,6 @@ export declare class AwsInstrumentation extends InstrumentationBase<AwsSdkInstru
|
|
|
18
18
|
private _getV3MiddlewareStackClonePatch;
|
|
19
19
|
private _getV3MiddlewareStackResolvePatch;
|
|
20
20
|
private _callOriginalFunction;
|
|
21
|
+
_updateMetricInstruments(): void;
|
|
21
22
|
}
|
|
22
23
|
//# sourceMappingURL=aws-sdk.d.ts.map
|
package/build/src/aws-sdk.js
CHANGED
|
@@ -29,7 +29,6 @@ const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
|
|
|
29
29
|
const V3_CLIENT_CONFIG_KEY = Symbol('opentelemetry.instrumentation.aws-sdk.client.config');
|
|
30
30
|
class AwsInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
31
31
|
static component = 'aws-sdk';
|
|
32
|
-
servicesExtensions = new services_1.ServicesExtensions();
|
|
33
32
|
constructor(config = {}) {
|
|
34
33
|
super(version_1.PACKAGE_NAME, version_1.PACKAGE_VERSION, config);
|
|
35
34
|
}
|
|
@@ -160,6 +159,7 @@ class AwsInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
160
159
|
const commandName = awsExecutionContext.commandName ?? command.constructor?.name;
|
|
161
160
|
const normalizedRequest = (0, utils_1.normalizeV3Request)(serviceName, commandName, command.input, undefined);
|
|
162
161
|
const requestMetadata = self.servicesExtensions.requestPreSpanHook(normalizedRequest, self.getConfig(), self._diag);
|
|
162
|
+
const startTime = (0, core_1.hrTime)();
|
|
163
163
|
const span = self._startAwsV3Span(normalizedRequest, requestMetadata);
|
|
164
164
|
const activeContextWithSpan = api_1.trace.setSpan(api_1.context.active(), span);
|
|
165
165
|
const handlerPromise = new Promise((resolve, reject) => {
|
|
@@ -198,7 +198,7 @@ class AwsInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
198
198
|
request: normalizedRequest,
|
|
199
199
|
requestId: requestId,
|
|
200
200
|
};
|
|
201
|
-
self.servicesExtensions.responseHook(normalizedResponse, span, self.tracer, self.getConfig());
|
|
201
|
+
self.servicesExtensions.responseHook(normalizedResponse, span, self.tracer, self.getConfig(), startTime);
|
|
202
202
|
self._callUserResponseHook(span, normalizedResponse);
|
|
203
203
|
return response;
|
|
204
204
|
})
|
|
@@ -247,6 +247,12 @@ class AwsInstrumentation extends instrumentation_1.InstrumentationBase {
|
|
|
247
247
|
return originalFunction();
|
|
248
248
|
}
|
|
249
249
|
}
|
|
250
|
+
_updateMetricInstruments() {
|
|
251
|
+
if (!this.servicesExtensions) {
|
|
252
|
+
this.servicesExtensions = new services_1.ServicesExtensions();
|
|
253
|
+
}
|
|
254
|
+
this.servicesExtensions.updateMetricInstruments(this.meter);
|
|
255
|
+
}
|
|
250
256
|
}
|
|
251
257
|
exports.AwsInstrumentation = AwsInstrumentation;
|
|
252
258
|
//# sourceMappingURL=aws-sdk.js.map
|
package/build/src/aws-sdk.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aws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,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;;AA9YU,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 { 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 private servicesExtensions: ServicesExtensions = new 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 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 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 self.servicesExtensions.responseHook(\n normalizedResponse,\n span,\n self.tracer,\n self.getConfig()\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 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 _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"]}
|
|
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,EACrC,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,IAAI,CAAC,CACxC,CAAC;QAEF,uFAAuF;QACvF,mDAAmD;QACnD,4EAA4E;QAC5E,MAAM,iBAAiB,GAAG,IAAI,qDAAmC,CAC/D,2BAA2B,EAC3B,CAAC,QAAQ,CAAC,EACV,SAAS,EACT,SAAS,EACT,CAAC,gCAAgC,EAAE,gC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AA,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;;AAxZU,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.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 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 self.servicesExtensions.responseHook(\n normalizedResponse,\n span,\n self.tracer,\n self.getConfig(),\n startTime\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 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 _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"]}
|
package/build/src/semconv.d.ts
CHANGED
|
@@ -75,6 +75,15 @@ export declare const ATTR_GEN_AI_RESPONSE_FINISH_REASONS: "gen_ai.response.finis
|
|
|
75
75
|
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
76
76
|
*/
|
|
77
77
|
export declare const ATTR_GEN_AI_SYSTEM: "gen_ai.system";
|
|
78
|
+
/**
|
|
79
|
+
* The type of token being counted.
|
|
80
|
+
*
|
|
81
|
+
* @example input
|
|
82
|
+
* @example output
|
|
83
|
+
*
|
|
84
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
85
|
+
*/
|
|
86
|
+
export declare const ATTR_GEN_AI_TOKEN_TYPE: "gen_ai.token.type";
|
|
78
87
|
/**
|
|
79
88
|
* The number of tokens used in the GenAI input (prompt).
|
|
80
89
|
*
|
|
@@ -99,4 +108,12 @@ export declare const GEN_AI_OPERATION_NAME_VALUE_CHAT: "chat";
|
|
|
99
108
|
* Enum value "aws.bedrock" for attribute {@link ATTR_GEN_AI_SYSTEM}.
|
|
100
109
|
*/
|
|
101
110
|
export declare const GEN_AI_SYSTEM_VALUE_AWS_BEDROCK: "aws.bedrock";
|
|
111
|
+
/**
|
|
112
|
+
* Enum value "input" for attribute {@link ATTR_GEN_AI_TOKEN_TYPE}.
|
|
113
|
+
*/
|
|
114
|
+
export declare const GEN_AI_TOKEN_TYPE_VALUE_INPUT: "input";
|
|
115
|
+
/**
|
|
116
|
+
* Enum value "output" for attribute {@link ATTR_GEN_AI_TOKEN_TYPE}.
|
|
117
|
+
*/
|
|
118
|
+
export declare const GEN_AI_TOKEN_TYPE_VALUE_OUTPUT: "output";
|
|
102
119
|
//# sourceMappingURL=semconv.d.ts.map
|
package/build/src/semconv.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.GEN_AI_SYSTEM_VALUE_AWS_BEDROCK = exports.GEN_AI_OPERATION_NAME_VALUE_CHAT = exports.ATTR_GEN_AI_USAGE_OUTPUT_TOKENS = exports.ATTR_GEN_AI_USAGE_INPUT_TOKENS = exports.ATTR_GEN_AI_SYSTEM = exports.ATTR_GEN_AI_RESPONSE_FINISH_REASONS = exports.ATTR_GEN_AI_REQUEST_TOP_P = exports.ATTR_GEN_AI_REQUEST_TEMPERATURE = exports.ATTR_GEN_AI_REQUEST_STOP_SEQUENCES = exports.ATTR_GEN_AI_REQUEST_MODEL = exports.ATTR_GEN_AI_REQUEST_MAX_TOKENS = exports.ATTR_GEN_AI_OPERATION_NAME = void 0;
|
|
18
|
+
exports.GEN_AI_TOKEN_TYPE_VALUE_OUTPUT = exports.GEN_AI_TOKEN_TYPE_VALUE_INPUT = exports.GEN_AI_SYSTEM_VALUE_AWS_BEDROCK = exports.GEN_AI_OPERATION_NAME_VALUE_CHAT = exports.ATTR_GEN_AI_USAGE_OUTPUT_TOKENS = exports.ATTR_GEN_AI_USAGE_INPUT_TOKENS = exports.ATTR_GEN_AI_TOKEN_TYPE = exports.ATTR_GEN_AI_SYSTEM = exports.ATTR_GEN_AI_RESPONSE_FINISH_REASONS = exports.ATTR_GEN_AI_REQUEST_TOP_P = exports.ATTR_GEN_AI_REQUEST_TEMPERATURE = exports.ATTR_GEN_AI_REQUEST_STOP_SEQUENCES = exports.ATTR_GEN_AI_REQUEST_MODEL = exports.ATTR_GEN_AI_REQUEST_MAX_TOKENS = exports.ATTR_GEN_AI_OPERATION_NAME = void 0;
|
|
19
19
|
/*
|
|
20
20
|
* This file contains a copy of unstable semantic convention definitions
|
|
21
21
|
* used by this package.
|
|
@@ -98,6 +98,15 @@ exports.ATTR_GEN_AI_RESPONSE_FINISH_REASONS = 'gen_ai.response.finish_reasons';
|
|
|
98
98
|
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
99
99
|
*/
|
|
100
100
|
exports.ATTR_GEN_AI_SYSTEM = 'gen_ai.system';
|
|
101
|
+
/**
|
|
102
|
+
* The type of token being counted.
|
|
103
|
+
*
|
|
104
|
+
* @example input
|
|
105
|
+
* @example output
|
|
106
|
+
*
|
|
107
|
+
* @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
|
|
108
|
+
*/
|
|
109
|
+
exports.ATTR_GEN_AI_TOKEN_TYPE = 'gen_ai.token.type';
|
|
101
110
|
/**
|
|
102
111
|
* The number of tokens used in the GenAI input (prompt).
|
|
103
112
|
*
|
|
@@ -122,4 +131,12 @@ exports.GEN_AI_OPERATION_NAME_VALUE_CHAT = 'chat';
|
|
|
122
131
|
* Enum value "aws.bedrock" for attribute {@link ATTR_GEN_AI_SYSTEM}.
|
|
123
132
|
*/
|
|
124
133
|
exports.GEN_AI_SYSTEM_VALUE_AWS_BEDROCK = 'aws.bedrock';
|
|
134
|
+
/**
|
|
135
|
+
* Enum value "input" for attribute {@link ATTR_GEN_AI_TOKEN_TYPE}.
|
|
136
|
+
*/
|
|
137
|
+
exports.GEN_AI_TOKEN_TYPE_VALUE_INPUT = 'input';
|
|
138
|
+
/**
|
|
139
|
+
* Enum value "output" for attribute {@link ATTR_GEN_AI_TOKEN_TYPE}.
|
|
140
|
+
*/
|
|
141
|
+
exports.GEN_AI_TOKEN_TYPE_VALUE_OUTPUT = 'output';
|
|
125
142
|
//# sourceMappingURL=semconv.js.map
|
package/build/src/semconv.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"semconv.js","sourceRoot":"","sources":["../../src/semconv.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH;;;;GAIG;AAEH;;;;;;GAMG;AACU,QAAA,0BAA0B,GAAG,uBAAgC,CAAC;AAE3E;;;;;;GAMG;AACU,QAAA,8BAA8B,GACzC,2BAAoC,CAAC;AAEvC;;;;;;GAMG;AACU,QAAA,yBAAyB,GAAG,sBAA+B,CAAC;AAEzE;;;;;;GAMG;AACU,QAAA,kCAAkC,GAC7C,+BAAwC,CAAC;AAE3C;;;;;;GAMG;AACU,QAAA,+BAA+B,GAC1C,4BAAqC,CAAC;AAExC;;;;;;GAMG;AACU,QAAA,yBAAyB,GAAG,sBAA+B,CAAC;AAEzE;;;;;;;GAOG;AACU,QAAA,mCAAmC,GAC9C,gCAAyC,CAAC;AAE5C;;;;;;;;;;;;;;;;;;GAkBG;AACU,QAAA,kBAAkB,GAAG,eAAwB,CAAC;AAE3D;;;;;;GAMG;AACU,QAAA,8BAA8B,GACzC,2BAAoC,CAAC;AAEvC;;;;;;GAMG;AACU,QAAA,+BAA+B,GAC1C,4BAAqC,CAAC;AAExC;;GAEG;AACU,QAAA,gCAAgC,GAAG,MAAe,CAAC;AAEhE;;GAEG;AACU,QAAA,+BAA+B,GAAG,aAAsB,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/*\n * This file contains a copy of unstable semantic convention definitions\n * used by this package.\n * @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv\n */\n\n/**\n * The name of the operation being performed.\n *\n * @note If one of the predefined values applies, but specific system uses a different name it's **RECOMMENDED** to document it in the semantic conventions for specific GenAI system and use system-specific name in the instrumentation. If a different name is not documented, instrumentation libraries **SHOULD** use applicable predefined value.\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_GEN_AI_OPERATION_NAME = 'gen_ai.operation.name' as const;\n\n/**\n * The maximum number of tokens the model generates for a request.\n *\n * @example 100\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_GEN_AI_REQUEST_MAX_TOKENS =\n 'gen_ai.request.max_tokens' as const;\n\n/**\n * The name of the GenAI model a request is being made to.\n *\n * @example \"gpt-4\"\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_GEN_AI_REQUEST_MODEL = 'gen_ai.request.model' as const;\n\n/**\n * List of sequences that the model will use to stop generating further tokens.\n *\n * @example [\"forest\", \"lived\"]\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_GEN_AI_REQUEST_STOP_SEQUENCES =\n 'gen_ai.request.stop_sequences' as const;\n\n/**\n * The temperature setting for the GenAI request.\n *\n * @example 0.0\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_GEN_AI_REQUEST_TEMPERATURE =\n 'gen_ai.request.temperature' as const;\n\n/**\n * The top_p sampling setting for the GenAI request.\n *\n * @example 1.0\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_GEN_AI_REQUEST_TOP_P = 'gen_ai.request.top_p' as const;\n\n/**\n * Array of reasons the model stopped generating tokens, corresponding to each generation received.\n *\n * @example [\"stop\"]\n * @example [\"stop\", \"length\"]\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_GEN_AI_RESPONSE_FINISH_REASONS =\n 'gen_ai.response.finish_reasons' as const;\n\n/**\n * The Generative AI product as identified by the client or server instrumentation.\n *\n * @example \"openai\"\n *\n * @note The `gen_ai.system` describes a family of GenAI models with specific model identified\n * by `gen_ai.request.model` and `gen_ai.response.model` attributes.\n *\n * The actual GenAI product may differ from the one identified by the client.\n * Multiple systems, including Azure OpenAI and Gemini, are accessible by OpenAI client\n * libraries. In such cases, the `gen_ai.system` is set to `openai` based on the\n * instrumentation's best knowledge, instead of the actual system. The `server.address`\n * attribute may help identify the actual system in use for `openai`.\n *\n * For custom model, a custom friendly name **SHOULD** be used.\n * If none of these options apply, the `gen_ai.system` **SHOULD** be set to `_OTHER`.\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_GEN_AI_SYSTEM = 'gen_ai.system' as const;\n\n/**\n * The number of tokens used in the GenAI input (prompt).\n *\n * @example 100\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_GEN_AI_USAGE_INPUT_TOKENS =\n 'gen_ai.usage.input_tokens' as const;\n\n/**\n * The number of tokens used in the GenAI response (completion).\n *\n * @example 180\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_GEN_AI_USAGE_OUTPUT_TOKENS =\n 'gen_ai.usage.output_tokens' as const;\n\n/**\n * Enum value \"chat\" for attribute {@link ATTR_GEN_AI_OPERATION_NAME}.\n */\nexport const GEN_AI_OPERATION_NAME_VALUE_CHAT = 'chat' as const;\n\n/**\n * Enum value \"aws.bedrock\" for attribute {@link ATTR_GEN_AI_SYSTEM}.\n */\nexport const GEN_AI_SYSTEM_VALUE_AWS_BEDROCK = 'aws.bedrock' as const;\n"]}
|
|
1
|
+
{"version":3,"file":"semconv.js","sourceRoot":"","sources":["../../src/semconv.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH;;;;GAIG;AAEH;;;;;;GAMG;AACU,QAAA,0BAA0B,GAAG,uBAAgC,CAAC;AAE3E;;;;;;GAMG;AACU,QAAA,8BAA8B,GACzC,2BAAoC,CAAC;AAEvC;;;;;;GAMG;AACU,QAAA,yBAAyB,GAAG,sBAA+B,CAAC;AAEzE;;;;;;GAMG;AACU,QAAA,kCAAkC,GAC7C,+BAAwC,CAAC;AAE3C;;;;;;GAMG;AACU,QAAA,+BAA+B,GAC1C,4BAAqC,CAAC;AAExC;;;;;;GAMG;AACU,QAAA,yBAAyB,GAAG,sBAA+B,CAAC;AAEzE;;;;;;;GAOG;AACU,QAAA,mCAAmC,GAC9C,gCAAyC,CAAC;AAE5C;;;;;;;;;;;;;;;;;;GAkBG;AACU,QAAA,kBAAkB,GAAG,eAAwB,CAAC;AAE3D;;;;;;;GAOG;AACU,QAAA,sBAAsB,GAAG,mBAA4B,CAAC;AAEnE;;;;;;GAMG;AACU,QAAA,8BAA8B,GACzC,2BAAoC,CAAC;AAEvC;;;;;;GAMG;AACU,QAAA,+BAA+B,GAC1C,4BAAqC,CAAC;AAExC;;GAEG;AACU,QAAA,gCAAgC,GAAG,MAAe,CAAC;AAEhE;;GAEG;AACU,QAAA,+BAA+B,GAAG,aAAsB,CAAC;AAEtE;;GAEG;AACU,QAAA,6BAA6B,GAAG,OAAgB,CAAC;AAE9D;;GAEG;AACU,QAAA,8BAA8B,GAAG,QAAiB,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/*\n * This file contains a copy of unstable semantic convention definitions\n * used by this package.\n * @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv\n */\n\n/**\n * The name of the operation being performed.\n *\n * @note If one of the predefined values applies, but specific system uses a different name it's **RECOMMENDED** to document it in the semantic conventions for specific GenAI system and use system-specific name in the instrumentation. If a different name is not documented, instrumentation libraries **SHOULD** use applicable predefined value.\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_GEN_AI_OPERATION_NAME = 'gen_ai.operation.name' as const;\n\n/**\n * The maximum number of tokens the model generates for a request.\n *\n * @example 100\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_GEN_AI_REQUEST_MAX_TOKENS =\n 'gen_ai.request.max_tokens' as const;\n\n/**\n * The name of the GenAI model a request is being made to.\n *\n * @example \"gpt-4\"\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_GEN_AI_REQUEST_MODEL = 'gen_ai.request.model' as const;\n\n/**\n * List of sequences that the model will use to stop generating further tokens.\n *\n * @example [\"forest\", \"lived\"]\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_GEN_AI_REQUEST_STOP_SEQUENCES =\n 'gen_ai.request.stop_sequences' as const;\n\n/**\n * The temperature setting for the GenAI request.\n *\n * @example 0.0\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_GEN_AI_REQUEST_TEMPERATURE =\n 'gen_ai.request.temperature' as const;\n\n/**\n * The top_p sampling setting for the GenAI request.\n *\n * @example 1.0\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_GEN_AI_REQUEST_TOP_P = 'gen_ai.request.top_p' as const;\n\n/**\n * Array of reasons the model stopped generating tokens, corresponding to each generation received.\n *\n * @example [\"stop\"]\n * @example [\"stop\", \"length\"]\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_GEN_AI_RESPONSE_FINISH_REASONS =\n 'gen_ai.response.finish_reasons' as const;\n\n/**\n * The Generative AI product as identified by the client or server instrumentation.\n *\n * @example \"openai\"\n *\n * @note The `gen_ai.system` describes a family of GenAI models with specific model identified\n * by `gen_ai.request.model` and `gen_ai.response.model` attributes.\n *\n * The actual GenAI product may differ from the one identified by the client.\n * Multiple systems, including Azure OpenAI and Gemini, are accessible by OpenAI client\n * libraries. In such cases, the `gen_ai.system` is set to `openai` based on the\n * instrumentation's best knowledge, instead of the actual system. The `server.address`\n * attribute may help identify the actual system in use for `openai`.\n *\n * For custom model, a custom friendly name **SHOULD** be used.\n * If none of these options apply, the `gen_ai.system` **SHOULD** be set to `_OTHER`.\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_GEN_AI_SYSTEM = 'gen_ai.system' as const;\n\n/**\n * The type of token being counted.\n *\n * @example input\n * @example output\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_GEN_AI_TOKEN_TYPE = 'gen_ai.token.type' as const;\n\n/**\n * The number of tokens used in the GenAI input (prompt).\n *\n * @example 100\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_GEN_AI_USAGE_INPUT_TOKENS =\n 'gen_ai.usage.input_tokens' as const;\n\n/**\n * The number of tokens used in the GenAI response (completion).\n *\n * @example 180\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_GEN_AI_USAGE_OUTPUT_TOKENS =\n 'gen_ai.usage.output_tokens' as const;\n\n/**\n * Enum value \"chat\" for attribute {@link ATTR_GEN_AI_OPERATION_NAME}.\n */\nexport const GEN_AI_OPERATION_NAME_VALUE_CHAT = 'chat' as const;\n\n/**\n * Enum value \"aws.bedrock\" for attribute {@link ATTR_GEN_AI_SYSTEM}.\n */\nexport const GEN_AI_SYSTEM_VALUE_AWS_BEDROCK = 'aws.bedrock' as const;\n\n/**\n * Enum value \"input\" for attribute {@link ATTR_GEN_AI_TOKEN_TYPE}.\n */\nexport const GEN_AI_TOKEN_TYPE_VALUE_INPUT = 'input' as const;\n\n/**\n * Enum value \"output\" for attribute {@link ATTR_GEN_AI_TOKEN_TYPE}.\n */\nexport const GEN_AI_TOKEN_TYPE_VALUE_OUTPUT = 'output' as const;\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DiagLogger, Span, SpanAttributes, SpanKind, Tracer } from '@opentelemetry/api';
|
|
1
|
+
import { DiagLogger, HrTime, Meter, Span, SpanAttributes, SpanKind, Tracer } from '@opentelemetry/api';
|
|
2
2
|
import { AwsSdkInstrumentationConfig, NormalizedRequest, NormalizedResponse } from '../types';
|
|
3
3
|
export interface RequestMetadata {
|
|
4
4
|
isIncoming: boolean;
|
|
@@ -9,6 +9,7 @@ export interface RequestMetadata {
|
|
|
9
9
|
export interface ServiceExtension {
|
|
10
10
|
requestPreSpanHook: (request: NormalizedRequest, config: AwsSdkInstrumentationConfig, diag: DiagLogger) => RequestMetadata;
|
|
11
11
|
requestPostSpanHook?: (request: NormalizedRequest) => void;
|
|
12
|
-
responseHook?: (response: NormalizedResponse, span: Span, tracer: Tracer, config: AwsSdkInstrumentationConfig) => void;
|
|
12
|
+
responseHook?: (response: NormalizedResponse, span: Span, tracer: Tracer, config: AwsSdkInstrumentationConfig, startTime: HrTime) => void;
|
|
13
|
+
updateMetricInstruments?: (meter: Meter) => void;
|
|
13
14
|
}
|
|
14
15
|
//# sourceMappingURL=ServiceExtension.d.ts.map
|
|
@@ -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 {\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
|
+
{"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 HrTime,\n Meter,\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 startTime: HrTime\n ) => void;\n\n updateMetricInstruments?: (meter: Meter) => void;\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Tracer, Span, DiagLogger } from '@opentelemetry/api';
|
|
1
|
+
import { Tracer, Span, DiagLogger, Meter, HrTime } 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 {
|
|
@@ -6,6 +6,7 @@ export declare class ServicesExtensions implements ServiceExtension {
|
|
|
6
6
|
constructor();
|
|
7
7
|
requestPreSpanHook(request: NormalizedRequest, config: AwsSdkInstrumentationConfig, diag: DiagLogger): RequestMetadata;
|
|
8
8
|
requestPostSpanHook(request: NormalizedRequest): void;
|
|
9
|
-
responseHook(response: NormalizedResponse, span: Span, tracer: Tracer, config: AwsSdkInstrumentationConfig): void;
|
|
9
|
+
responseHook(response: NormalizedResponse, span: Span, tracer: Tracer, config: AwsSdkInstrumentationConfig, startTime: HrTime): void;
|
|
10
|
+
updateMetricInstruments(meter: Meter): void;
|
|
10
11
|
}
|
|
11
12
|
//# sourceMappingURL=ServicesExtensions.d.ts.map
|
|
@@ -33,9 +33,14 @@ class ServicesExtensions {
|
|
|
33
33
|
return;
|
|
34
34
|
return serviceExtension.requestPostSpanHook(request);
|
|
35
35
|
}
|
|
36
|
-
responseHook(response, span, tracer, config) {
|
|
36
|
+
responseHook(response, span, tracer, config, startTime) {
|
|
37
37
|
const serviceExtension = this.services.get(response.request.serviceName);
|
|
38
|
-
serviceExtension?.responseHook?.(response, span, tracer, config);
|
|
38
|
+
serviceExtension?.responseHook?.(response, span, tracer, config, startTime);
|
|
39
|
+
}
|
|
40
|
+
updateMetricInstruments(meter) {
|
|
41
|
+
for (const serviceExtension of this.services.values()) {
|
|
42
|
+
serviceExtension.updateMetricInstruments?.(meter);
|
|
43
|
+
}
|
|
39
44
|
}
|
|
40
45
|
}
|
|
41
46
|
exports.ServicesExtensions = ServicesExtensions;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServicesExtensions.js","sourceRoot":"","sources":["../../../src/services/ServicesExtensions.ts"],"names":[],"mappings":";;;AA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AAO,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,gBAAgB,EAAE,mBAAmB;YAAE,OAAO;QACnD,OAAO,gBAAgB,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC;IACvD,CAAC;IAED,YAAY,CACV,QAA4B,EAC5B,IAAU,EACV,MAAc,EACd,MAAmC,EACnC,SAAiB;QAEjB,MAAM,gBAAgB,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QACzE,gBAAgB,EAAE,YAAY,EAAE,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;IAC9E,CAAC;IAED,uBAAuB,CAAC,KAAY;QAClC,KAAK,MAAM,gBAAgB,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE;YACrD,gBAAgB,CAAC,uBAAuB,EAAE,CAAC,KAAK,CAAC,CAAC;SACnD;IACH,CAAC;CACF;AAhDD,gDAgDC","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, Meter, HrTime } from '@opentelemetry/api';\nimport { ServiceExtension, RequestMetadata } from './ServiceExtension';\nimport { SqsServiceExtension } from './sqs';\nimport {\n AwsSdkInstrumentationConfig,\n NormalizedRequest,\n NormalizedResponse,\n} from '../types';\nimport { BedrockRuntimeServiceExtension } from './bedrock-runtime';\nimport { DynamodbServiceExtension } from './dynamodb';\nimport { SnsServiceExtension } from './sns';\nimport { LambdaServiceExtension } from './lambda';\nimport { S3ServiceExtension } from './s3';\nimport { KinesisServiceExtension } from './kinesis';\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 this.services.set('S3', new S3ServiceExtension());\n this.services.set('Kinesis', new KinesisServiceExtension());\n this.services.set('BedrockRuntime', new BedrockRuntimeServiceExtension());\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 startTime: HrTime\n ) {\n const serviceExtension = this.services.get(response.request.serviceName);\n serviceExtension?.responseHook?.(response, span, tracer, config, startTime);\n }\n\n updateMetricInstruments(meter: Meter) {\n for (const serviceExtension of this.services.values()) {\n serviceExtension.updateMetricInstruments?.(meter);\n }\n }\n}\n"]}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { DiagLogger, Span, Tracer } from '@opentelemetry/api';
|
|
1
|
+
import { DiagLogger, HrTime, Meter, 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 BedrockRuntimeServiceExtension implements ServiceExtension {
|
|
5
|
+
private tokenUsage;
|
|
6
|
+
private operationDuration;
|
|
7
|
+
updateMetricInstruments(meter: Meter): void;
|
|
5
8
|
requestPreSpanHook(request: NormalizedRequest, config: AwsSdkInstrumentationConfig, diag: DiagLogger): RequestMetadata;
|
|
6
9
|
private requestPreSpanHookConverse;
|
|
7
10
|
private requestPreSpanHookInvokeModel;
|
|
8
|
-
responseHook(response: NormalizedResponse, span: Span, tracer: Tracer, config: AwsSdkInstrumentationConfig): void;
|
|
11
|
+
responseHook(response: NormalizedResponse, span: Span, tracer: Tracer, config: AwsSdkInstrumentationConfig, startTime: HrTime): void;
|
|
9
12
|
private responseHookConverse;
|
|
10
13
|
private responseHookInvokeModel;
|
|
11
14
|
}
|
|
@@ -1,8 +1,52 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BedrockRuntimeServiceExtension = void 0;
|
|
4
|
+
/*
|
|
5
|
+
* Copyright The OpenTelemetry Authors
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
const api_1 = require("@opentelemetry/api");
|
|
4
20
|
const semconv_1 = require("../semconv");
|
|
21
|
+
const core_1 = require("@opentelemetry/core");
|
|
5
22
|
class BedrockRuntimeServiceExtension {
|
|
23
|
+
tokenUsage;
|
|
24
|
+
operationDuration;
|
|
25
|
+
updateMetricInstruments(meter) {
|
|
26
|
+
// https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-metrics/#metric-gen_aiclienttokenusage
|
|
27
|
+
this.tokenUsage = meter.createHistogram('gen_ai.client.token.usage', {
|
|
28
|
+
unit: '{token}',
|
|
29
|
+
description: 'Measures number of input and output tokens used',
|
|
30
|
+
valueType: api_1.ValueType.INT,
|
|
31
|
+
advice: {
|
|
32
|
+
explicitBucketBoundaries: [
|
|
33
|
+
1, 4, 16, 64, 256, 1024, 4096, 16384, 65536, 262144, 1048576, 4194304,
|
|
34
|
+
16777216, 67108864,
|
|
35
|
+
],
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
// https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-metrics/#metric-gen_aiclientoperationduration
|
|
39
|
+
this.operationDuration = meter.createHistogram('gen_ai.client.operation.duration', {
|
|
40
|
+
unit: 's',
|
|
41
|
+
description: 'GenAI operation duration',
|
|
42
|
+
advice: {
|
|
43
|
+
explicitBucketBoundaries: [
|
|
44
|
+
0.01, 0.02, 0.04, 0.08, 0.16, 0.32, 0.64, 1.28, 2.56, 5.12, 10.24,
|
|
45
|
+
20.48, 40.96, 81.92,
|
|
46
|
+
],
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
}
|
|
6
50
|
requestPreSpanHook(request, config, diag) {
|
|
7
51
|
switch (request.commandName) {
|
|
8
52
|
case 'Converse':
|
|
@@ -203,26 +247,41 @@ class BedrockRuntimeServiceExtension {
|
|
|
203
247
|
spanAttributes,
|
|
204
248
|
};
|
|
205
249
|
}
|
|
206
|
-
responseHook(response, span, tracer, config) {
|
|
250
|
+
responseHook(response, span, tracer, config, startTime) {
|
|
207
251
|
if (!span.isRecording()) {
|
|
208
252
|
return;
|
|
209
253
|
}
|
|
210
254
|
switch (response.request.commandName) {
|
|
211
255
|
case 'Converse':
|
|
212
|
-
return this.responseHookConverse(response, span, tracer, config);
|
|
256
|
+
return this.responseHookConverse(response, span, tracer, config, startTime);
|
|
213
257
|
case 'InvokeModel':
|
|
214
258
|
return this.responseHookInvokeModel(response, span, tracer, config);
|
|
215
259
|
}
|
|
216
260
|
}
|
|
217
|
-
responseHookConverse(response, span, tracer, config) {
|
|
261
|
+
responseHookConverse(response, span, tracer, config, startTime) {
|
|
218
262
|
const { stopReason, usage } = response.data;
|
|
263
|
+
const sharedMetricAttrs = {
|
|
264
|
+
[semconv_1.ATTR_GEN_AI_SYSTEM]: semconv_1.GEN_AI_SYSTEM_VALUE_AWS_BEDROCK,
|
|
265
|
+
[semconv_1.ATTR_GEN_AI_OPERATION_NAME]: semconv_1.GEN_AI_OPERATION_NAME_VALUE_CHAT,
|
|
266
|
+
[semconv_1.ATTR_GEN_AI_REQUEST_MODEL]: response.request.commandInput.modelId,
|
|
267
|
+
};
|
|
268
|
+
const durationSecs = (0, core_1.hrTimeToMilliseconds)((0, core_1.hrTimeDuration)(startTime, (0, core_1.hrTime)())) / 1000;
|
|
269
|
+
this.operationDuration.record(durationSecs, sharedMetricAttrs);
|
|
219
270
|
if (usage) {
|
|
220
271
|
const { inputTokens, outputTokens } = usage;
|
|
221
272
|
if (inputTokens !== undefined) {
|
|
222
273
|
span.setAttribute(semconv_1.ATTR_GEN_AI_USAGE_INPUT_TOKENS, inputTokens);
|
|
274
|
+
this.tokenUsage.record(inputTokens, {
|
|
275
|
+
...sharedMetricAttrs,
|
|
276
|
+
[semconv_1.ATTR_GEN_AI_TOKEN_TYPE]: semconv_1.GEN_AI_TOKEN_TYPE_VALUE_INPUT,
|
|
277
|
+
});
|
|
223
278
|
}
|
|
224
279
|
if (outputTokens !== undefined) {
|
|
225
280
|
span.setAttribute(semconv_1.ATTR_GEN_AI_USAGE_OUTPUT_TOKENS, outputTokens);
|
|
281
|
+
this.tokenUsage.record(outputTokens, {
|
|
282
|
+
...sharedMetricAttrs,
|
|
283
|
+
[semconv_1.ATTR_GEN_AI_TOKEN_TYPE]: semconv_1.GEN_AI_TOKEN_TYPE_VALUE_OUTPUT,
|
|
284
|
+
});
|
|
226
285
|
}
|
|
227
286
|
}
|
|
228
287
|
if (stopReason !== undefined) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bedrock-runtime.js","sourceRoot":"","sources":["../../../src/services/bedrock-runtime.ts"],"names":[],"mappings":";;;AAiBA,wCAaoB;AAOpB,MAAa,8BAA8B;IACzC,kBAAkB,CAChB,OAA0B,EAC1B,MAAmC,EACnC,IAAgB;QAEhB,QAAQ,OAAO,CAAC,WAAW,EAAE;YAC3B,KAAK,UAAU;gBACb,OAAO,IAAI,CAAC,0BAA0B,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;YAChE,KAAK,aAAa;gBAChB,OAAO,IAAI,CAAC,6BAA6B,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;SACpE;QAED,OAAO;YACL,UAAU,EAAE,KAAK;SAClB,CAAC;IACJ,CAAC;IAEO,0BAA0B,CAChC,OAA0B,EAC1B,MAAmC,EACnC,IAAgB;QAEhB,IAAI,QAAQ,GAAG,0CAAgC,CAAC;QAChD,MAAM,cAAc,GAAe;YACjC,CAAC,4BAAkB,CAAC,EAAE,yCAA+B;YACrD,CAAC,oCAA0B,CAAC,EAAE,0CAAgC;SAC/D,CAAC;QAEF,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC;QAC7C,IAAI,OAAO,EAAE;YACX,cAAc,CAAC,mCAAyB,CAAC,GAAG,OAAO,CAAC;YACpD,IAAI,QAAQ,EAAE;gBACZ,QAAQ,IAAI,IA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\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 { Attributes, DiagLogger, Span, Tracer } from '@opentelemetry/api';\nimport { RequestMetadata, ServiceExtension } from './ServiceExtension';\nimport {\n ATTR_GEN_AI_SYSTEM,\n ATTR_GEN_AI_OPERATION_NAME,\n ATTR_GEN_AI_REQUEST_MODEL,\n ATTR_GEN_AI_REQUEST_MAX_TOKENS,\n ATTR_GEN_AI_REQUEST_TEMPERATURE,\n ATTR_GEN_AI_REQUEST_TOP_P,\n ATTR_GEN_AI_REQUEST_STOP_SEQUENCES,\n ATTR_GEN_AI_USAGE_INPUT_TOKENS,\n ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,\n ATTR_GEN_AI_RESPONSE_FINISH_REASONS,\n GEN_AI_OPERATION_NAME_VALUE_CHAT,\n GEN_AI_SYSTEM_VALUE_AWS_BEDROCK,\n} from '../semconv';\nimport {\n AwsSdkInstrumentationConfig,\n NormalizedRequest,\n NormalizedResponse,\n} from '../types';\n\nexport class BedrockRuntimeServiceExtension implements ServiceExtension {\n requestPreSpanHook(\n request: NormalizedRequest,\n config: AwsSdkInstrumentationConfig,\n diag: DiagLogger\n ): RequestMetadata {\n switch (request.commandName) {\n case 'Converse':\n return this.requestPreSpanHookConverse(request, config, diag);\n case 'InvokeModel':\n return this.requestPreSpanHookInvokeModel(request, config, diag);\n }\n\n return {\n isIncoming: false,\n };\n }\n\n private requestPreSpanHookConverse(\n request: NormalizedRequest,\n config: AwsSdkInstrumentationConfig,\n diag: DiagLogger\n ): RequestMetadata {\n let spanName = GEN_AI_OPERATION_NAME_VALUE_CHAT;\n const spanAttributes: Attributes = {\n [ATTR_GEN_AI_SYSTEM]: GEN_AI_SYSTEM_VALUE_AWS_BEDROCK,\n [ATTR_GEN_AI_OPERATION_NAME]: GEN_AI_OPERATION_NAME_VALUE_CHAT,\n };\n\n const modelId = request.commandInput.modelId;\n if (modelId) {\n spanAttributes[ATTR_GEN_AI_REQUEST_MODEL] = modelId;\n if (spanName) {\n spanName += ` ${modelId}`;\n }\n }\n\n const inferenceConfig = request.commandInput.inferenceConfig;\n if (inferenceConfig) {\n const { maxTokens, temperature, topP, stopSequences } = inferenceConfig;\n if (maxTokens !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_MAX_TOKENS] = maxTokens;\n }\n if (temperature !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TEMPERATURE] = temperature;\n }\n if (topP !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TOP_P] = topP;\n }\n if (stopSequences !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_STOP_SEQUENCES] = stopSequences;\n }\n }\n\n return {\n spanName,\n isIncoming: false,\n spanAttributes,\n };\n }\n\n private requestPreSpanHookInvokeModel(\n request: NormalizedRequest,\n config: AwsSdkInstrumentationConfig,\n diag: DiagLogger\n ): RequestMetadata {\n let spanName: string | undefined;\n const spanAttributes: Attributes = {\n [ATTR_GEN_AI_SYSTEM]: GEN_AI_SYSTEM_VALUE_AWS_BEDROCK,\n // add operation name for InvokeModel API\n };\n\n const modelId = request.commandInput?.modelId;\n if (modelId) {\n spanAttributes[ATTR_GEN_AI_REQUEST_MODEL] = modelId;\n }\n\n if (request.commandInput?.body) {\n const requestBody = JSON.parse(request.commandInput.body);\n if (modelId.includes('amazon.titan')) {\n if (requestBody.textGenerationConfig?.temperature !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TEMPERATURE] =\n requestBody.textGenerationConfig.temperature;\n }\n if (requestBody.textGenerationConfig?.topP !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TOP_P] =\n requestBody.textGenerationConfig.topP;\n }\n if (requestBody.textGenerationConfig?.maxTokenCount !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_MAX_TOKENS] =\n requestBody.textGenerationConfig.maxTokenCount;\n }\n if (requestBody.textGenerationConfig?.stopSequences !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_STOP_SEQUENCES] =\n requestBody.textGenerationConfig.stopSequences;\n }\n } else if (modelId.includes('amazon.nova')) {\n if (requestBody.inferenceConfig?.temperature !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TEMPERATURE] =\n requestBody.inferenceConfig.temperature;\n }\n if (requestBody.inferenceConfig?.top_p !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TOP_P] =\n requestBody.inferenceConfig.top_p;\n }\n if (requestBody.inferenceConfig?.max_new_tokens !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_MAX_TOKENS] =\n requestBody.inferenceConfig.max_new_tokens;\n }\n if (requestBody.inferenceConfig?.stopSequences !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_STOP_SEQUENCES] =\n requestBody.inferenceConfig.stopSequences;\n }\n } else if (modelId.includes('anthropic.claude')) {\n if (requestBody.max_tokens !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_MAX_TOKENS] =\n requestBody.max_tokens;\n }\n if (requestBody.temperature !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TEMPERATURE] =\n requestBody.temperature;\n }\n if (requestBody.top_p !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TOP_P] = requestBody.top_p;\n }\n if (requestBody.stop_sequences !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_STOP_SEQUENCES] =\n requestBody.stop_sequences;\n }\n } else if (modelId.includes('meta.llama')) {\n if (requestBody.max_gen_len !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_MAX_TOKENS] =\n requestBody.max_gen_len;\n }\n if (requestBody.temperature !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TEMPERATURE] =\n requestBody.temperature;\n }\n if (requestBody.top_p !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TOP_P] = requestBody.top_p;\n }\n // request for meta llama models does not contain stop_sequences field\n } else if (modelId.includes('cohere.command-r')) {\n if (requestBody.max_tokens !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_MAX_TOKENS] =\n requestBody.max_tokens;\n }\n if (requestBody.temperature !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TEMPERATURE] =\n requestBody.temperature;\n }\n if (requestBody.p !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TOP_P] = requestBody.p;\n }\n if (requestBody.message !== undefined) {\n // NOTE: We approximate the token count since this value is not directly available in the body\n // According to Bedrock docs they use (total_chars / 6) to approximate token count for pricing.\n // https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-prepare.html\n spanAttributes[ATTR_GEN_AI_USAGE_INPUT_TOKENS] = Math.ceil(\n requestBody.message.length / 6\n );\n }\n if (requestBody.stop_sequences !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_STOP_SEQUENCES] =\n requestBody.stop_sequences;\n }\n } else if (modelId.includes('cohere.command')) {\n if (requestBody.max_tokens !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_MAX_TOKENS] =\n requestBody.max_tokens;\n }\n if (requestBody.temperature !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TEMPERATURE] =\n requestBody.temperature;\n }\n if (requestBody.p !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TOP_P] = requestBody.p;\n }\n if (requestBody.prompt !== undefined) {\n // NOTE: We approximate the token count since this value is not directly available in the body\n // According to Bedrock docs they use (total_chars / 6) to approximate token count for pricing.\n // https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-prepare.html\n spanAttributes[ATTR_GEN_AI_USAGE_INPUT_TOKENS] = Math.ceil(\n requestBody.prompt.length / 6\n );\n }\n if (requestBody.stop_sequences !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_STOP_SEQUENCES] =\n requestBody.stop_sequences;\n }\n } else if (modelId.includes('mistral')) {\n if (requestBody.prompt !== undefined) {\n // NOTE: We approximate the token count since this value is not directly available in the body\n // According to Bedrock docs they use (total_chars / 6) to approximate token count for pricing.\n // https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-prepare.html\n spanAttributes[ATTR_GEN_AI_USAGE_INPUT_TOKENS] = Math.ceil(\n requestBody.prompt.length / 6\n );\n }\n if (requestBody.max_tokens !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_MAX_TOKENS] =\n requestBody.max_tokens;\n }\n if (requestBody.temperature !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TEMPERATURE] =\n requestBody.temperature;\n }\n if (requestBody.top_p !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TOP_P] = requestBody.top_p;\n }\n if (requestBody.stop !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_STOP_SEQUENCES] = requestBody.stop;\n }\n }\n }\n\n return {\n spanName,\n isIncoming: false,\n spanAttributes,\n };\n }\n\n responseHook(\n response: NormalizedResponse,\n span: Span,\n tracer: Tracer,\n config: AwsSdkInstrumentationConfig\n ) {\n if (!span.isRecording()) {\n return;\n }\n\n switch (response.request.commandName) {\n case 'Converse':\n return this.responseHookConverse(response, span, tracer, config);\n case 'InvokeModel':\n return this.responseHookInvokeModel(response, span, tracer, config);\n }\n }\n\n private responseHookConverse(\n response: NormalizedResponse,\n span: Span,\n tracer: Tracer,\n config: AwsSdkInstrumentationConfig\n ) {\n const { stopReason, usage } = response.data;\n if (usage) {\n const { inputTokens, outputTokens } = usage;\n if (inputTokens !== undefined) {\n span.setAttribute(ATTR_GEN_AI_USAGE_INPUT_TOKENS, inputTokens);\n }\n if (outputTokens !== undefined) {\n span.setAttribute(ATTR_GEN_AI_USAGE_OUTPUT_TOKENS, outputTokens);\n }\n }\n\n if (stopReason !== undefined) {\n span.setAttribute(ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [stopReason]);\n }\n }\n\n private responseHookInvokeModel(\n response: NormalizedResponse,\n span: Span,\n tracer: Tracer,\n config: AwsSdkInstrumentationConfig\n ) {\n const currentModelId = response.request.commandInput?.modelId;\n if (response.data?.body) {\n const decodedResponseBody = new TextDecoder().decode(response.data.body);\n const responseBody = JSON.parse(decodedResponseBody);\n if (currentModelId.includes('amazon.titan')) {\n if (responseBody.inputTextTokenCount !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_INPUT_TOKENS,\n responseBody.inputTextTokenCount\n );\n }\n if (responseBody.results?.[0]?.tokenCount !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,\n responseBody.results[0].tokenCount\n );\n }\n if (responseBody.results?.[0]?.completionReason !== undefined) {\n span.setAttribute(ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [\n responseBody.results[0].completionReason,\n ]);\n }\n } else if (currentModelId.includes('amazon.nova')) {\n if (responseBody.usage !== undefined) {\n if (responseBody.usage.inputTokens !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_INPUT_TOKENS,\n responseBody.usage.inputTokens\n );\n }\n if (responseBody.usage.outputTokens !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,\n responseBody.usage.outputTokens\n );\n }\n }\n if (responseBody.stopReason !== undefined) {\n span.setAttribute(ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [\n responseBody.stopReason,\n ]);\n }\n } else if (currentModelId.includes('anthropic.claude')) {\n if (responseBody.usage?.input_tokens !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_INPUT_TOKENS,\n responseBody.usage.input_tokens\n );\n }\n if (responseBody.usage?.output_tokens !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,\n responseBody.usage.output_tokens\n );\n }\n if (responseBody.stop_reason !== undefined) {\n span.setAttribute(ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [\n responseBody.stop_reason,\n ]);\n }\n } else if (currentModelId.includes('meta.llama')) {\n if (responseBody.prompt_token_count !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_INPUT_TOKENS,\n responseBody.prompt_token_count\n );\n }\n if (responseBody.generation_token_count !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,\n responseBody.generation_token_count\n );\n }\n if (responseBody.stop_reason !== undefined) {\n span.setAttribute(ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [\n responseBody.stop_reason,\n ]);\n }\n } else if (currentModelId.includes('cohere.command-r')) {\n if (responseBody.text !== undefined) {\n // NOTE: We approximate the token count since this value is not directly available in the body\n // According to Bedrock docs they use (total_chars / 6) to approximate token count for pricing.\n // https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-prepare.html\n span.setAttribute(\n ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,\n Math.ceil(responseBody.text.length / 6)\n );\n }\n if (responseBody.finish_reason !== undefined) {\n span.setAttribute(ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [\n responseBody.finish_reason,\n ]);\n }\n } else if (currentModelId.includes('cohere.command')) {\n if (responseBody.generations?.[0]?.text !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,\n // NOTE: We approximate the token count since this value is not directly available in the body\n // According to Bedrock docs they use (total_chars / 6) to approximate token count for pricing.\n // https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-prepare.html\n Math.ceil(responseBody.generations[0].text.length / 6)\n );\n }\n if (responseBody.generations?.[0]?.finish_reason !== undefined) {\n span.setAttribute(ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [\n responseBody.generations[0].finish_reason,\n ]);\n }\n } else if (currentModelId.includes('mistral')) {\n if (responseBody.outputs?.[0]?.text !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,\n // NOTE: We approximate the token count since this value is not directly available in the body\n // According to Bedrock docs they use (total_chars / 6) to approximate token count for pricing.\n // https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-prepare.html\n Math.ceil(responseBody.outputs[0].text.length / 6)\n );\n }\n if (responseBody.outputs?.[0]?.stop_reason !== undefined) {\n span.setAttribute(ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [\n responseBody.outputs[0].stop_reason,\n ]);\n }\n }\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"bedrock-runtime.js","sourceRoot":"","sources":["../../../src/services/bedrock-runtime.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,4CAS4B;AAE5B,wCAgBoB;AAMpB,8CAI6B;AAE7B,MAAa,8BAA8B;IACjC,UAAU,CAAa;IACvB,iBAAiB,CAAa;IAEtC,uBAAuB,CAAC,KAAY;QAClC,mGAAmG;QACnG,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC,eAAe,CAAC,2BAA2B,EAAE;YACnE,IAAI,EAAE,SAAS;YACf,WAAW,EAAE,iDAAiD;YAC9D,SAAS,EAAE,eAAS,CAAC,GAAG;YACxB,MAAM,EAAE;gBACN,wBAAwB,EAAE;oBACxB,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;oBACrE,QAAQ,EAAE,QAAQ;iBACnB;aACF;SACF,CAAC,CAAC;QAEH,0GAA0G;QAC1G,IAAI,CAAC,iBAAiB,GAAG,KAAK,CAAC,eAAe,CAC5C,kCAAkC,EAClC;YACE,IAAI,EAAE,GAAG;YACT,WAAW,EAAE,0BAA0B;YACvC,MAAM,EAAE;gBACN,wBAAwB,EAAE;oBACxB,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAA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G,CAAC,CAAC,CACnD,CAAC;iBACH;gBACD,IAAI,YAAY,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,KAAK,SAAS,EAAE;oBACxD,IAAI,CAAC,YAAY,CAAC,6CAAmC,EAAE;wBACrD,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,WAAW;qBACpC,CAAC,CAAC;iBACJ;aACF;SACF;IACH,CAAC;CACF;AAzcD,wEAycC","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 Attributes,\n DiagLogger,\n Histogram,\n HrTime,\n Meter,\n Span,\n Tracer,\n ValueType,\n} from '@opentelemetry/api';\nimport { RequestMetadata, ServiceExtension } from './ServiceExtension';\nimport {\n ATTR_GEN_AI_SYSTEM,\n ATTR_GEN_AI_OPERATION_NAME,\n ATTR_GEN_AI_REQUEST_MODEL,\n ATTR_GEN_AI_REQUEST_MAX_TOKENS,\n ATTR_GEN_AI_REQUEST_TEMPERATURE,\n ATTR_GEN_AI_REQUEST_TOP_P,\n ATTR_GEN_AI_REQUEST_STOP_SEQUENCES,\n ATTR_GEN_AI_TOKEN_TYPE,\n ATTR_GEN_AI_USAGE_INPUT_TOKENS,\n ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,\n ATTR_GEN_AI_RESPONSE_FINISH_REASONS,\n GEN_AI_OPERATION_NAME_VALUE_CHAT,\n GEN_AI_SYSTEM_VALUE_AWS_BEDROCK,\n GEN_AI_TOKEN_TYPE_VALUE_INPUT,\n GEN_AI_TOKEN_TYPE_VALUE_OUTPUT,\n} from '../semconv';\nimport {\n AwsSdkInstrumentationConfig,\n NormalizedRequest,\n NormalizedResponse,\n} from '../types';\nimport {\n hrTime,\n hrTimeDuration,\n hrTimeToMilliseconds,\n} from '@opentelemetry/core';\n\nexport class BedrockRuntimeServiceExtension implements ServiceExtension {\n private tokenUsage!: Histogram;\n private operationDuration!: Histogram;\n\n updateMetricInstruments(meter: Meter) {\n // https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-metrics/#metric-gen_aiclienttokenusage\n this.tokenUsage = meter.createHistogram('gen_ai.client.token.usage', {\n unit: '{token}',\n description: 'Measures number of input and output tokens used',\n valueType: ValueType.INT,\n advice: {\n explicitBucketBoundaries: [\n 1, 4, 16, 64, 256, 1024, 4096, 16384, 65536, 262144, 1048576, 4194304,\n 16777216, 67108864,\n ],\n },\n });\n\n // https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-metrics/#metric-gen_aiclientoperationduration\n this.operationDuration = meter.createHistogram(\n 'gen_ai.client.operation.duration',\n {\n unit: 's',\n description: 'GenAI operation duration',\n advice: {\n explicitBucketBoundaries: [\n 0.01, 0.02, 0.04, 0.08, 0.16, 0.32, 0.64, 1.28, 2.56, 5.12, 10.24,\n 20.48, 40.96, 81.92,\n ],\n },\n }\n );\n }\n\n requestPreSpanHook(\n request: NormalizedRequest,\n config: AwsSdkInstrumentationConfig,\n diag: DiagLogger\n ): RequestMetadata {\n switch (request.commandName) {\n case 'Converse':\n return this.requestPreSpanHookConverse(request, config, diag);\n case 'InvokeModel':\n return this.requestPreSpanHookInvokeModel(request, config, diag);\n }\n\n return {\n isIncoming: false,\n };\n }\n\n private requestPreSpanHookConverse(\n request: NormalizedRequest,\n config: AwsSdkInstrumentationConfig,\n diag: DiagLogger\n ): RequestMetadata {\n let spanName = GEN_AI_OPERATION_NAME_VALUE_CHAT;\n const spanAttributes: Attributes = {\n [ATTR_GEN_AI_SYSTEM]: GEN_AI_SYSTEM_VALUE_AWS_BEDROCK,\n [ATTR_GEN_AI_OPERATION_NAME]: GEN_AI_OPERATION_NAME_VALUE_CHAT,\n };\n\n const modelId = request.commandInput.modelId;\n if (modelId) {\n spanAttributes[ATTR_GEN_AI_REQUEST_MODEL] = modelId;\n if (spanName) {\n spanName += ` ${modelId}`;\n }\n }\n\n const inferenceConfig = request.commandInput.inferenceConfig;\n if (inferenceConfig) {\n const { maxTokens, temperature, topP, stopSequences } = inferenceConfig;\n if (maxTokens !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_MAX_TOKENS] = maxTokens;\n }\n if (temperature !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TEMPERATURE] = temperature;\n }\n if (topP !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TOP_P] = topP;\n }\n if (stopSequences !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_STOP_SEQUENCES] = stopSequences;\n }\n }\n\n return {\n spanName,\n isIncoming: false,\n spanAttributes,\n };\n }\n\n private requestPreSpanHookInvokeModel(\n request: NormalizedRequest,\n config: AwsSdkInstrumentationConfig,\n diag: DiagLogger\n ): RequestMetadata {\n let spanName: string | undefined;\n const spanAttributes: Attributes = {\n [ATTR_GEN_AI_SYSTEM]: GEN_AI_SYSTEM_VALUE_AWS_BEDROCK,\n // add operation name for InvokeModel API\n };\n\n const modelId = request.commandInput?.modelId;\n if (modelId) {\n spanAttributes[ATTR_GEN_AI_REQUEST_MODEL] = modelId;\n }\n\n if (request.commandInput?.body) {\n const requestBody = JSON.parse(request.commandInput.body);\n if (modelId.includes('amazon.titan')) {\n if (requestBody.textGenerationConfig?.temperature !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TEMPERATURE] =\n requestBody.textGenerationConfig.temperature;\n }\n if (requestBody.textGenerationConfig?.topP !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TOP_P] =\n requestBody.textGenerationConfig.topP;\n }\n if (requestBody.textGenerationConfig?.maxTokenCount !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_MAX_TOKENS] =\n requestBody.textGenerationConfig.maxTokenCount;\n }\n if (requestBody.textGenerationConfig?.stopSequences !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_STOP_SEQUENCES] =\n requestBody.textGenerationConfig.stopSequences;\n }\n } else if (modelId.includes('amazon.nova')) {\n if (requestBody.inferenceConfig?.temperature !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TEMPERATURE] =\n requestBody.inferenceConfig.temperature;\n }\n if (requestBody.inferenceConfig?.top_p !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TOP_P] =\n requestBody.inferenceConfig.top_p;\n }\n if (requestBody.inferenceConfig?.max_new_tokens !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_MAX_TOKENS] =\n requestBody.inferenceConfig.max_new_tokens;\n }\n if (requestBody.inferenceConfig?.stopSequences !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_STOP_SEQUENCES] =\n requestBody.inferenceConfig.stopSequences;\n }\n } else if (modelId.includes('anthropic.claude')) {\n if (requestBody.max_tokens !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_MAX_TOKENS] =\n requestBody.max_tokens;\n }\n if (requestBody.temperature !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TEMPERATURE] =\n requestBody.temperature;\n }\n if (requestBody.top_p !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TOP_P] = requestBody.top_p;\n }\n if (requestBody.stop_sequences !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_STOP_SEQUENCES] =\n requestBody.stop_sequences;\n }\n } else if (modelId.includes('meta.llama')) {\n if (requestBody.max_gen_len !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_MAX_TOKENS] =\n requestBody.max_gen_len;\n }\n if (requestBody.temperature !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TEMPERATURE] =\n requestBody.temperature;\n }\n if (requestBody.top_p !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TOP_P] = requestBody.top_p;\n }\n // request for meta llama models does not contain stop_sequences field\n } else if (modelId.includes('cohere.command-r')) {\n if (requestBody.max_tokens !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_MAX_TOKENS] =\n requestBody.max_tokens;\n }\n if (requestBody.temperature !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TEMPERATURE] =\n requestBody.temperature;\n }\n if (requestBody.p !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TOP_P] = requestBody.p;\n }\n if (requestBody.message !== undefined) {\n // NOTE: We approximate the token count since this value is not directly available in the body\n // According to Bedrock docs they use (total_chars / 6) to approximate token count for pricing.\n // https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-prepare.html\n spanAttributes[ATTR_GEN_AI_USAGE_INPUT_TOKENS] = Math.ceil(\n requestBody.message.length / 6\n );\n }\n if (requestBody.stop_sequences !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_STOP_SEQUENCES] =\n requestBody.stop_sequences;\n }\n } else if (modelId.includes('cohere.command')) {\n if (requestBody.max_tokens !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_MAX_TOKENS] =\n requestBody.max_tokens;\n }\n if (requestBody.temperature !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TEMPERATURE] =\n requestBody.temperature;\n }\n if (requestBody.p !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TOP_P] = requestBody.p;\n }\n if (requestBody.prompt !== undefined) {\n // NOTE: We approximate the token count since this value is not directly available in the body\n // According to Bedrock docs they use (total_chars / 6) to approximate token count for pricing.\n // https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-prepare.html\n spanAttributes[ATTR_GEN_AI_USAGE_INPUT_TOKENS] = Math.ceil(\n requestBody.prompt.length / 6\n );\n }\n if (requestBody.stop_sequences !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_STOP_SEQUENCES] =\n requestBody.stop_sequences;\n }\n } else if (modelId.includes('mistral')) {\n if (requestBody.prompt !== undefined) {\n // NOTE: We approximate the token count since this value is not directly available in the body\n // According to Bedrock docs they use (total_chars / 6) to approximate token count for pricing.\n // https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-prepare.html\n spanAttributes[ATTR_GEN_AI_USAGE_INPUT_TOKENS] = Math.ceil(\n requestBody.prompt.length / 6\n );\n }\n if (requestBody.max_tokens !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_MAX_TOKENS] =\n requestBody.max_tokens;\n }\n if (requestBody.temperature !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TEMPERATURE] =\n requestBody.temperature;\n }\n if (requestBody.top_p !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TOP_P] = requestBody.top_p;\n }\n if (requestBody.stop !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_STOP_SEQUENCES] = requestBody.stop;\n }\n }\n }\n\n return {\n spanName,\n isIncoming: false,\n spanAttributes,\n };\n }\n\n responseHook(\n response: NormalizedResponse,\n span: Span,\n tracer: Tracer,\n config: AwsSdkInstrumentationConfig,\n startTime: HrTime\n ) {\n if (!span.isRecording()) {\n return;\n }\n\n switch (response.request.commandName) {\n case 'Converse':\n return this.responseHookConverse(\n response,\n span,\n tracer,\n config,\n startTime\n );\n case 'InvokeModel':\n return this.responseHookInvokeModel(response, span, tracer, config);\n }\n }\n\n private responseHookConverse(\n response: NormalizedResponse,\n span: Span,\n tracer: Tracer,\n config: AwsSdkInstrumentationConfig,\n startTime: HrTime\n ) {\n const { stopReason, usage } = response.data;\n\n const sharedMetricAttrs: Attributes = {\n [ATTR_GEN_AI_SYSTEM]: GEN_AI_SYSTEM_VALUE_AWS_BEDROCK,\n [ATTR_GEN_AI_OPERATION_NAME]: GEN_AI_OPERATION_NAME_VALUE_CHAT,\n [ATTR_GEN_AI_REQUEST_MODEL]: response.request.commandInput.modelId,\n };\n\n const durationSecs =\n hrTimeToMilliseconds(hrTimeDuration(startTime, hrTime())) / 1000;\n this.operationDuration.record(durationSecs, sharedMetricAttrs);\n\n if (usage) {\n const { inputTokens, outputTokens } = usage;\n if (inputTokens !== undefined) {\n span.setAttribute(ATTR_GEN_AI_USAGE_INPUT_TOKENS, inputTokens);\n\n this.tokenUsage.record(inputTokens, {\n ...sharedMetricAttrs,\n [ATTR_GEN_AI_TOKEN_TYPE]: GEN_AI_TOKEN_TYPE_VALUE_INPUT,\n });\n }\n if (outputTokens !== undefined) {\n span.setAttribute(ATTR_GEN_AI_USAGE_OUTPUT_TOKENS, outputTokens);\n\n this.tokenUsage.record(outputTokens, {\n ...sharedMetricAttrs,\n [ATTR_GEN_AI_TOKEN_TYPE]: GEN_AI_TOKEN_TYPE_VALUE_OUTPUT,\n });\n }\n }\n\n if (stopReason !== undefined) {\n span.setAttribute(ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [stopReason]);\n }\n }\n\n private responseHookInvokeModel(\n response: NormalizedResponse,\n span: Span,\n tracer: Tracer,\n config: AwsSdkInstrumentationConfig\n ) {\n const currentModelId = response.request.commandInput?.modelId;\n if (response.data?.body) {\n const decodedResponseBody = new TextDecoder().decode(response.data.body);\n const responseBody = JSON.parse(decodedResponseBody);\n if (currentModelId.includes('amazon.titan')) {\n if (responseBody.inputTextTokenCount !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_INPUT_TOKENS,\n responseBody.inputTextTokenCount\n );\n }\n if (responseBody.results?.[0]?.tokenCount !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,\n responseBody.results[0].tokenCount\n );\n }\n if (responseBody.results?.[0]?.completionReason !== undefined) {\n span.setAttribute(ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [\n responseBody.results[0].completionReason,\n ]);\n }\n } else if (currentModelId.includes('amazon.nova')) {\n if (responseBody.usage !== undefined) {\n if (responseBody.usage.inputTokens !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_INPUT_TOKENS,\n responseBody.usage.inputTokens\n );\n }\n if (responseBody.usage.outputTokens !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,\n responseBody.usage.outputTokens\n );\n }\n }\n if (responseBody.stopReason !== undefined) {\n span.setAttribute(ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [\n responseBody.stopReason,\n ]);\n }\n } else if (currentModelId.includes('anthropic.claude')) {\n if (responseBody.usage?.input_tokens !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_INPUT_TOKENS,\n responseBody.usage.input_tokens\n );\n }\n if (responseBody.usage?.output_tokens !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,\n responseBody.usage.output_tokens\n );\n }\n if (responseBody.stop_reason !== undefined) {\n span.setAttribute(ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [\n responseBody.stop_reason,\n ]);\n }\n } else if (currentModelId.includes('meta.llama')) {\n if (responseBody.prompt_token_count !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_INPUT_TOKENS,\n responseBody.prompt_token_count\n );\n }\n if (responseBody.generation_token_count !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,\n responseBody.generation_token_count\n );\n }\n if (responseBody.stop_reason !== undefined) {\n span.setAttribute(ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [\n responseBody.stop_reason,\n ]);\n }\n } else if (currentModelId.includes('cohere.command-r')) {\n if (responseBody.text !== undefined) {\n // NOTE: We approximate the token count since this value is not directly available in the body\n // According to Bedrock docs they use (total_chars / 6) to approximate token count for pricing.\n // https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-prepare.html\n span.setAttribute(\n ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,\n Math.ceil(responseBody.text.length / 6)\n );\n }\n if (responseBody.finish_reason !== undefined) {\n span.setAttribute(ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [\n responseBody.finish_reason,\n ]);\n }\n } else if (currentModelId.includes('cohere.command')) {\n if (responseBody.generations?.[0]?.text !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,\n // NOTE: We approximate the token count since this value is not directly available in the body\n // According to Bedrock docs they use (total_chars / 6) to approximate token count for pricing.\n // https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-prepare.html\n Math.ceil(responseBody.generations[0].text.length / 6)\n );\n }\n if (responseBody.generations?.[0]?.finish_reason !== undefined) {\n span.setAttribute(ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [\n responseBody.generations[0].finish_reason,\n ]);\n }\n } else if (currentModelId.includes('mistral')) {\n if (responseBody.outputs?.[0]?.text !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,\n // NOTE: We approximate the token count since this value is not directly available in the body\n // According to Bedrock docs they use (total_chars / 6) to approximate token count for pricing.\n // https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-prepare.html\n Math.ceil(responseBody.outputs[0].text.length / 6)\n );\n }\n if (responseBody.outputs?.[0]?.stop_reason !== undefined) {\n span.setAttribute(ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [\n responseBody.outputs[0].stop_reason,\n ]);\n }\n }\n }\n }\n}\n"]}
|
package/build/src/version.d.ts
CHANGED
package/build/src/version.js
CHANGED
|
@@ -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.
|
|
20
|
+
exports.PACKAGE_VERSION = '0.53.0';
|
|
21
21
|
exports.PACKAGE_NAME = '@opentelemetry/instrumentation-aws-sdk';
|
|
22
22
|
//# sourceMappingURL=version.js.map
|
package/build/src/version.js.map
CHANGED
|
@@ -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.
|
|
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.53.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.
|
|
3
|
+
"version": "0.53.0",
|
|
4
4
|
"description": "OpenTelemetry instrumentation for `aws-sdk` and `@aws-sdk/client-*` clients for various AWS services",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"aws",
|
|
@@ -45,9 +45,9 @@
|
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@opentelemetry/core": "^2.0.0",
|
|
48
|
-
"@opentelemetry/instrumentation": "^0.
|
|
49
|
-
"@opentelemetry/propagation-utils": "^0.31.
|
|
50
|
-
"@opentelemetry/semantic-conventions": "^1.
|
|
48
|
+
"@opentelemetry/instrumentation": "^0.201.0",
|
|
49
|
+
"@opentelemetry/propagation-utils": "^0.31.1",
|
|
50
|
+
"@opentelemetry/semantic-conventions": "^1.31.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@aws-sdk/client-bedrock-runtime": "^3.587.0",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"@aws-sdk/client-sqs": "^3.85.0",
|
|
60
60
|
"@aws-sdk/types": "^3.370.0",
|
|
61
61
|
"@opentelemetry/api": "^1.3.0",
|
|
62
|
-
"@opentelemetry/contrib-test-utils": "^0.
|
|
62
|
+
"@opentelemetry/contrib-test-utils": "^0.47.0",
|
|
63
63
|
"@opentelemetry/sdk-trace-base": "^2.0.0",
|
|
64
64
|
"@smithy/node-http-handler": "2.4.0",
|
|
65
65
|
"@types/mocha": "10.0.10",
|
|
@@ -77,5 +77,5 @@
|
|
|
77
77
|
"engines": {
|
|
78
78
|
"node": "^18.19.0 || >=20.6.0"
|
|
79
79
|
},
|
|
80
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "393b51596dc869983a03ce8857658029ca122a15"
|
|
81
81
|
}
|