Skip to content

Commit 8f9a960

Browse files
fix(observability): vendor incubating semconv consts + correct service.version
- Stop re-exporting from @opentelemetry/semantic-conventions/incubating (OTel advises against depending on the unstable entry point); vendor the 4 needed experimental attribute names as plain constants in conventions.ts. - service.version: use the deployment revision (deploymentId) falling back to the framework version, not Deno.hostname() (which is instance identity). Addresses PR review (cubic P2 + coderabbit). Cache is already a single deco.cache.requests counter + deco.cache.status label (earlier commit). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent a4e8020 commit 8f9a960

3 files changed

Lines changed: 22 additions & 13 deletions

File tree

deps.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,10 @@ export {
8989
ATTR_USER_AGENT_ORIGINAL,
9090
METRIC_HTTP_SERVER_REQUEST_DURATION,
9191
} from "npm:@opentelemetry/semantic-conventions@1.37.0";
92-
// Incubating (not yet stable) semantic conventions.
93-
export {
94-
ATTR_CLOUD_PROVIDER,
95-
ATTR_CLOUD_REGION,
96-
ATTR_DEPLOYMENT_ENVIRONMENT_NAME,
97-
ATTR_HTTP_REQUEST_BODY_SIZE,
98-
ATTR_SERVICE_INSTANCE_ID,
99-
} from "npm:@opentelemetry/semantic-conventions@1.37.0/incubating";
92+
// Incubating (experimental) semconv names are NOT re-exported here — OTel
93+
// advises libraries against depending on the unstable `/incubating` entry
94+
// point. The few we need are vendored as plain constants in
95+
// observability/otel/conventions.ts.
10096

10197
export {
10298
ExplicitBucketHistogramAggregation,

observability/otel/config.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ import { Logger } from "@std/log/logger";
33
import { Context, context } from "../../deco.ts";
44
import denoJSON from "../../deno.json" with { type: "json" };
55
import {
6-
ATTR_CLOUD_PROVIDER,
7-
ATTR_CLOUD_REGION,
8-
ATTR_DEPLOYMENT_ENVIRONMENT_NAME,
9-
ATTR_SERVICE_INSTANCE_ID,
106
ATTR_SERVICE_NAME,
117
ATTR_SERVICE_VERSION,
128
BatchSpanProcessor,
@@ -18,6 +14,12 @@ import {
1814
registerInstrumentations,
1915
Resource,
2016
} from "../../deps.ts";
17+
import {
18+
ATTR_CLOUD_PROVIDER,
19+
ATTR_CLOUD_REGION,
20+
ATTR_DEPLOYMENT_ENVIRONMENT_NAME,
21+
ATTR_SERVICE_INSTANCE_ID,
22+
} from "./conventions.ts";
2123
import { DenoRuntimeInstrumentation } from "./instrumentation/deno-runtime.ts";
2224
import { DebugSampler } from "./samplers/debug.ts";
2325
import { type SamplingOptions, URLBasedSampler } from "./samplers/urlBased.ts";
@@ -40,7 +42,9 @@ const apps_ver = tryGetVersionOf("apps/") ??
4042
export const resource = Resource.default().merge(
4143
new Resource({
4244
[ATTR_SERVICE_NAME]: Deno.env.get(ENV_SITE_NAME) ?? "deco",
43-
[ATTR_SERVICE_VERSION]: Context.active().deploymentId ?? Deno.hostname(),
45+
// Version of the deployed artifact (the deployment revision), falling back
46+
// to the framework version — NOT the hostname (that is instance identity).
47+
[ATTR_SERVICE_VERSION]: Context.active().deploymentId ?? denoJSON.version,
4448
[ATTR_SERVICE_INSTANCE_ID]: crypto.randomUUID(),
4549
[ATTR_CLOUD_PROVIDER]: context.platform,
4650
"deco.runtime.version": denoJSON.version,

observability/otel/conventions.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,12 @@ export const ATTR_DECO_OPERATION_ERROR = "deco.operation.error";
1818
export const ATTR_DECO_CACHE_ENGINE = "deco.cache.engine";
1919
// Cache outcome: hit | stale | miss (| bypass). Same key on span + metric.
2020
export const ATTR_DECO_CACHE_STATUS = "deco.cache.status";
21+
22+
// Vendored copies of EXPERIMENTAL (incubating) OTel semconv attribute names.
23+
// OTel recommends libraries NOT import from `@opentelemetry/.../incubating`
24+
// (the entry point is unstable across versions); copy the values instead.
25+
// Sourced from @opentelemetry/semantic-conventions 1.37.0/incubating.
26+
export const ATTR_CLOUD_PROVIDER = "cloud.provider";
27+
export const ATTR_CLOUD_REGION = "cloud.region";
28+
export const ATTR_DEPLOYMENT_ENVIRONMENT_NAME = "deployment.environment.name";
29+
export const ATTR_SERVICE_INSTANCE_ID = "service.instance.id";

0 commit comments

Comments
 (0)