From d358c1c208b3f4ddea78ba6b721a1d0c1a557342 Mon Sep 17 00:00:00 2001 From: Umuoy Date: Tue, 9 Aug 2022 11:07:33 +0800 Subject: [PATCH] fix(example): fix koa example (#1088) --- examples/koa/client.js | 4 ++-- examples/koa/tracer.js | 12 +++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/examples/koa/client.js b/examples/koa/client.js index d766b18a82..77a6966925 100644 --- a/examples/koa/client.js +++ b/examples/koa/client.js @@ -13,10 +13,10 @@ function makeRequest() { api.context.with(api.trace.setSpan(api.ROOT_CONTEXT, span), async () => { try { const res = await axios.get('http://localhost:8081/run_test'); - span.setStatus({ code: api.StatusCode.OK }); + span.setStatus({ code: api.SpanStatusCode.OK }); console.log(res.statusText); } catch (e) { - span.setStatus({ code: api.StatusCode.ERROR, message: e.message }); + span.setStatus({ code: api.SpanStatusCode.ERROR, message: e.message }); } span.end(); console.log('Sleeping 5 seconds before shutdown to ensure all records are flushed.'); diff --git a/examples/koa/tracer.js b/examples/koa/tracer.js index 752b36cf1f..5e4aff4fa8 100644 --- a/examples/koa/tracer.js +++ b/examples/koa/tracer.js @@ -9,17 +9,23 @@ const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node'); const { SimpleSpanProcessor } = require('@opentelemetry/sdk-trace-base'); const { JaegerExporter } = require('@opentelemetry/exporter-jaeger'); const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin'); +const { Resource } = require('@opentelemetry/resources') +const { SemanticResourceAttributes } = require('@opentelemetry/semantic-conventions') const EXPORTER = process.env.EXPORTER || ''; module.exports = (serviceName) => { - const provider = new NodeTracerProvider(); + const provider = new NodeTracerProvider({ + resource: new Resource({ + [SemanticResourceAttributes.SERVICE_NAME]: serviceName + }) + }); let exporter; if (EXPORTER === 'jaeger') { - exporter = new JaegerExporter({ serviceName }); + exporter = new JaegerExporter(); } else { - exporter = new ZipkinExporter({ serviceName }); + exporter = new ZipkinExporter(); } provider.addSpanProcessor(new SimpleSpanProcessor(exporter));