Skip to content

Commit

Permalink
chore(examples/express): use exported strings for attributes (#2121)
Browse files Browse the repository at this point in the history
Use exported strings for Semantic Resource Attributes

Signed-off-by: maryliag <marylia.gutierrez@grafana.com>
Refs: #2025
  • Loading branch information
maryliag committed Apr 25, 2024
1 parent 7f5f20c commit 7822461
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/express/package.json
Expand Up @@ -40,7 +40,7 @@
"@opentelemetry/resources": "^1.18.1",
"@opentelemetry/sdk-trace-base": "^1.18.1",
"@opentelemetry/sdk-trace-node": "^1.18.1",
"@opentelemetry/semantic-conventions": "^1.18.1",
"@opentelemetry/semantic-conventions": "^1.23.0",
"axios": "^1.6.0",
"cross-env": "^7.0.3",
"express": "^4.17.1"
Expand Down
6 changes: 3 additions & 3 deletions examples/express/src/tracer.ts
Expand Up @@ -14,7 +14,7 @@ import { Sampler, AlwaysOnSampler, SimpleSpanProcessor } from '@opentelemetry/sd
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-proto';
import { ZipkinExporter } from '@opentelemetry/exporter-zipkin';
import { Resource } from '@opentelemetry/resources';
import { SemanticAttributes, SemanticResourceAttributes as ResourceAttributesSC } from '@opentelemetry/semantic-conventions';
import { SEMRESATTRS_SERVICE_NAME, SEMATTRS_HTTP_ROUTE } from '@opentelemetry/semantic-conventions';

const Exporter = (process.env.EXPORTER || '').toLowerCase().startsWith('z') ? ZipkinExporter : OTLPTraceExporter;
import { ExpressInstrumentation } from '@opentelemetry/instrumentation-express';
Expand All @@ -23,7 +23,7 @@ const { HttpInstrumentation } = require('@opentelemetry/instrumentation-http');
export const setupTracing = (serviceName: string) => {
const provider = new NodeTracerProvider({
resource: new Resource({
[ResourceAttributesSC.SERVICE_NAME]: serviceName,
[SEMRESATTRS_SERVICE_NAME]: serviceName,
}),
sampler: filterSampler(ignoreHealthCheck, new AlwaysOnSampler()),
});
Expand Down Expand Up @@ -65,5 +65,5 @@ function filterSampler(filterFn: FilterFunction, parent: Sampler): Sampler {
}

function ignoreHealthCheck(spanName: string, spanKind: SpanKind, attributes: Attributes) {
return spanKind !== opentelemetry.SpanKind.SERVER || attributes[SemanticAttributes.HTTP_ROUTE] !== "/health";
return spanKind !== opentelemetry.SpanKind.SERVER || attributes[SEMATTRS_HTTP_ROUTE] !== "/health";
}

0 comments on commit 7822461

Please sign in to comment.