Skip to content

Commit

Permalink
fix(example): fix koa example (#1088)
Browse files Browse the repository at this point in the history
  • Loading branch information
umuoy1 authored Aug 9, 2022
1 parent 845f50c commit d358c1c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions examples/koa/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
Expand Down
12 changes: 9 additions & 3 deletions examples/koa/tracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down

0 comments on commit d358c1c

Please sign in to comment.