From ed78bdee149ef4b4ba5406a22b8af9965fcc472b Mon Sep 17 00:00:00 2001 From: Francesco Gringl-Novy Date: Wed, 27 May 2026 14:13:45 +0200 Subject: [PATCH 1/2] ref(node): Refactor `hrTime` and related usage in vendored code Getting rid of this usage from `@opentelemetry/core`. --- .agents/skills/vendor-otel/SKILL.md | 2 ++ .../src/integration/aws/vendored/aws-sdk.ts | 6 +++--- .../aws/vendored/services/ServiceExtension.ts | 4 ++-- .../aws/vendored/services/ServicesExtensions.ts | 4 ++-- .../aws/vendored/services/bedrock-runtime.ts | 16 ++++++++-------- .../integrations/node-fetch/vendored/undici.ts | 13 ++++++------- .../tracing/amqplib/vendored/amqplib.ts | 10 +++++----- .../tracing/amqplib/vendored/utils.ts | 4 ++-- .../tracing/postgres/vendored/instrumentation.ts | 10 ++++------ 9 files changed, 34 insertions(+), 35 deletions(-) diff --git a/.agents/skills/vendor-otel/SKILL.md b/.agents/skills/vendor-otel/SKILL.md index 3f9555b32349..309b7701d757 100644 --- a/.agents/skills/vendor-otel/SKILL.md +++ b/.agents/skills/vendor-otel/SKILL.md @@ -9,6 +9,8 @@ description: Vendor an OpenTelemetry instrumentation package into the Sentry Jav Copy upstream OTel instrumentation TypeScript source into a `vendored/` directory, remove the npm dependency, and ensure builds and tests pass. No logic changes — the vendored code must behave identically to the original. +**Scope of this rule:** "No logic changes" applies **only to the initial vendoring PR**. After a package has been vendored, the `vendored/` directory is Sentry-owned source and follow-up PRs may refactor, simplify, replace upstream utilities with Sentry equivalents (e.g. `@opentelemetry/core` → `@sentry/core`), or otherwise diverge from upstream. Such cleanup is desired, not discouraged. + ## 1. Research Find upstream source files: diff --git a/packages/aws-serverless/src/integration/aws/vendored/aws-sdk.ts b/packages/aws-serverless/src/integration/aws/vendored/aws-sdk.ts index 0fb87e79186d..b20c1387d72a 100644 --- a/packages/aws-serverless/src/integration/aws/vendored/aws-sdk.ts +++ b/packages/aws-serverless/src/integration/aws/vendored/aws-sdk.ts @@ -20,7 +20,7 @@ /* eslint-disable */ import { Span, SpanKind, context, trace, diag, SpanStatusCode } from '@opentelemetry/api'; -import { hrTime, suppressTracing } from '@opentelemetry/core'; +import { suppressTracing } from '@opentelemetry/core'; import { AttributeNames } from './enums'; import { ServicesExtensions } from './services'; import { @@ -57,7 +57,7 @@ import { propwrap } from './propwrap'; import { RequestMetadata } from './services/ServiceExtension'; import { ATTR_HTTP_STATUS_CODE } from './semconv'; import { ATTR_HTTP_RESPONSE_STATUS_CODE } from '@opentelemetry/semantic-conventions'; -import { SDK_VERSION } from '@sentry/core'; +import { SDK_VERSION, timestampInSeconds } from '@sentry/core'; const PACKAGE_NAME = '@sentry/instrumentation-aws-sdk'; @@ -298,7 +298,7 @@ export class AwsInstrumentation extends InstrumentationBase any | undefined; updateMetricInstruments?: (meter: Meter) => void; diff --git a/packages/aws-serverless/src/integration/aws/vendored/services/ServicesExtensions.ts b/packages/aws-serverless/src/integration/aws/vendored/services/ServicesExtensions.ts index a7b7e6f2d05e..c055154a8a4f 100644 --- a/packages/aws-serverless/src/integration/aws/vendored/services/ServicesExtensions.ts +++ b/packages/aws-serverless/src/integration/aws/vendored/services/ServicesExtensions.ts @@ -19,7 +19,7 @@ */ /* eslint-disable */ -import { Tracer, Span, DiagLogger, Meter, HrTime } from '@opentelemetry/api'; +import { Tracer, Span, DiagLogger, Meter } from '@opentelemetry/api'; import { SemconvStability } from '@opentelemetry/instrumentation'; import { ServiceExtension, RequestMetadata } from './ServiceExtension'; import { SqsServiceExtension } from './sqs'; @@ -77,7 +77,7 @@ export class ServicesExtensions implements ServiceExtension { span: Span, tracer: Tracer, config: AwsSdkInstrumentationConfig, - startTime: HrTime, + startTime: number, ) { const serviceExtension = this.services.get(response.request.serviceName); diff --git a/packages/aws-serverless/src/integration/aws/vendored/services/bedrock-runtime.ts b/packages/aws-serverless/src/integration/aws/vendored/services/bedrock-runtime.ts index 77e9ada8960f..3c4d58e63302 100644 --- a/packages/aws-serverless/src/integration/aws/vendored/services/bedrock-runtime.ts +++ b/packages/aws-serverless/src/integration/aws/vendored/services/bedrock-runtime.ts @@ -19,7 +19,7 @@ */ /* eslint-disable */ -import { Attributes, DiagLogger, diag, Histogram, HrTime, Meter, Span, Tracer, ValueType } from '@opentelemetry/api'; +import { Attributes, DiagLogger, diag, Histogram, Meter, Span, Tracer, ValueType } from '@opentelemetry/api'; import { RequestMetadata, ServiceExtension } from './ServiceExtension'; import { ATTR_GEN_AI_SYSTEM, @@ -41,7 +41,7 @@ import { METRIC_GEN_AI_CLIENT_TOKEN_USAGE, } from '../semconv'; import { AwsSdkInstrumentationConfig, NormalizedRequest, NormalizedResponse } from '../types'; -import { hrTime, hrTimeDuration, hrTimeToMilliseconds } from '@opentelemetry/core'; +import { timestampInSeconds } from '@sentry/core'; // Simplified types inlined from @aws-sdk/client-bedrock-runtime // Only the fields accessed by this instrumentation are included @@ -295,7 +295,7 @@ export class BedrockRuntimeServiceExtension implements ServiceExtension { span: Span, tracer: Tracer, config: AwsSdkInstrumentationConfig, - startTime: HrTime, + startTime: number, ) { if (!span.isRecording()) { return; @@ -318,7 +318,7 @@ export class BedrockRuntimeServiceExtension implements ServiceExtension { span: Span, tracer: Tracer, config: AwsSdkInstrumentationConfig, - startTime: HrTime, + startTime: number, ) { const { stopReason, usage } = response.data; @@ -331,7 +331,7 @@ export class BedrockRuntimeServiceExtension implements ServiceExtension { span: Span, tracer: Tracer, config: AwsSdkInstrumentationConfig, - startTime: HrTime, + startTime: number, ) { return { ...response.data, @@ -345,7 +345,7 @@ export class BedrockRuntimeServiceExtension implements ServiceExtension { response: NormalizedResponse, stream: AsyncIterable, span: Span, - startTime: HrTime, + startTime: number, ) { try { let usage: TokenUsage | undefined; @@ -366,14 +366,14 @@ export class BedrockRuntimeServiceExtension implements ServiceExtension { } } - private setUsage(response: NormalizedResponse, span: Span, usage: TokenUsage | undefined, startTime: HrTime) { + private setUsage(response: NormalizedResponse, span: Span, usage: TokenUsage | undefined, startTime: number) { const sharedMetricAttrs: Attributes = { [ATTR_GEN_AI_SYSTEM]: GEN_AI_SYSTEM_VALUE_AWS_BEDROCK, [ATTR_GEN_AI_OPERATION_NAME]: GEN_AI_OPERATION_NAME_VALUE_CHAT, [ATTR_GEN_AI_REQUEST_MODEL]: response.request.commandInput.modelId, }; - const durationSecs = hrTimeToMilliseconds(hrTimeDuration(startTime, hrTime())) / 1000; + const durationSecs = timestampInSeconds() - startTime; this.operationDuration.record(durationSecs, sharedMetricAttrs); if (usage) { diff --git a/packages/node/src/integrations/node-fetch/vendored/undici.ts b/packages/node/src/integrations/node-fetch/vendored/undici.ts index 55e09d7c4d53..79aef5ee8964 100644 --- a/packages/node/src/integrations/node-fetch/vendored/undici.ts +++ b/packages/node/src/integrations/node-fetch/vendored/undici.ts @@ -25,7 +25,7 @@ import * as diagch from 'diagnostics_channel'; import { URL } from 'url'; import { InstrumentationBase, safeExecuteInTheMiddle } from '@opentelemetry/instrumentation'; -import type { Attributes, Histogram, HrTime, Span } from '@opentelemetry/api'; +import type { Attributes, Histogram, Span } from '@opentelemetry/api'; import { context, INVALID_SPAN_CONTEXT, @@ -35,7 +35,6 @@ import { trace, ValueType, } from '@opentelemetry/api'; -import { hrTime, hrTimeDuration, hrTimeToMilliseconds } from '@opentelemetry/core'; import { ATTR_ERROR_TYPE, ATTR_HTTP_REQUEST_METHOD, @@ -62,12 +61,12 @@ import type { } from './internal-types'; import type { UndiciInstrumentationConfig, UndiciRequest } from './types'; -import { SDK_VERSION } from '@sentry/core'; +import { SDK_VERSION, timestampInSeconds } from '@sentry/core'; interface InstrumentationRecord { span: Span; attributes: Attributes; - startTime: HrTime; + startTime: number; } const PACKAGE_NAME = '@sentry/instrumentation-undici'; @@ -225,7 +224,7 @@ export class UndiciInstrumentation extends InstrumentationBase Date: Wed, 27 May 2026 14:15:11 +0200 Subject: [PATCH 2/2] remove unneeded nestjs dependency --- packages/nestjs/package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/nestjs/package.json b/packages/nestjs/package.json index b123295a6a52..2876c1f5db95 100644 --- a/packages/nestjs/package.json +++ b/packages/nestjs/package.json @@ -45,7 +45,6 @@ }, "dependencies": { "@opentelemetry/api": "^1.9.1", - "@opentelemetry/core": "^2.6.1", "@opentelemetry/instrumentation": "^0.214.0", "@opentelemetry/semantic-conventions": "^1.40.0", "@sentry/core": "10.54.0",