Skip to content

Commit

Permalink
chore: add jaeger example
Browse files Browse the repository at this point in the history
  • Loading branch information
carolinee21 committed Jul 14, 2020
1 parent d5b70c6 commit a6959ae
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
File renamed without changes
File renamed without changes
Binary file removed examples/koa/jaeger.png
Binary file not shown.
13 changes: 9 additions & 4 deletions examples/koa/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async function setUp () {
*/
const posts = ["post 0", "post 1", "post 2"];

async function addPost(ctx) {
async function addPost(ctx, next) {
posts.push("post " + posts.length);
console.log("addPost");
const currentSpan = tracer.getCurrentSpan();
Expand All @@ -38,8 +38,8 @@ async function addPost(ctx) {
const viewNewPost = ctx.redirect(`/post/3`);
}

async function showNewPost(ctx) {
console.log("showPost");
async function showNewPost(ctx, next) {
console.log("showNewPost");
const id = ctx.params.id;
const post = posts[id];
if (!post) ctx.throw(404, 'Invalid post id');
Expand All @@ -48,8 +48,13 @@ async function showNewPost(ctx) {

async function runTest (ctx, next) {
console.log("runTest");
const currentSpan = tracer.getCurrentSpan();
const { traceId } = currentSpan.context();
console.log(`traceid: ${traceId}`);
console.log(`Jaeger URL: http://localhost:16686/trace/${traceId}`);
console.log(`Zipkin URL: http://localhost:9411/zipkin/traces/${traceId}`);
ctx.body = "All posts: " + posts;
const addNewPost = ctx.redirect(`/post/new`);
const addNewPost = await ctx.redirect(`/post/new`);
}

function no_op (ctx, next) {
Expand Down
12 changes: 6 additions & 6 deletions examples/koa/tracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ module.exports = (serviceName) => {
},
});

provider.addSpanProcessor(new SimpleSpanProcessor(new ZipkinExporter({
serviceName,
})));
provider.addSpanProcessor(new SimpleSpanProcessor(new JaegerExporter({
serviceName,
})));

if (process.env.EXPORTER == 'jaeger') {
provider.addSpanProcessor(new SimpleSpanProcessor(new JaegerExporter({serviceName})));
} else {
provider.addSpanProcessor(new SimpleSpanProcessor(new ZipkinExporter({serviceName})));
}

// Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings
provider.register();
Expand Down

0 comments on commit a6959ae

Please sign in to comment.