chankamlam/nest-jaeger

You can only call finish() on a span once

Closed this issue · 5 comments

I got this error:

JAEGER ERROR operation=a606ec7f53b3a4767a14fb134b648003-164176fd6fc21a2a.elb.us-east-1.amazonaws.com/api/v1/roles,context=6e8567e0b4adb68d:6e8567e0b4adb68d:0:1#You can only call finish() on a span once.

I got this error:

JAEGER ERROR operation=a606ec7f53b3a4767a14fb134b648003-164176fd6fc21a2a.elb.us-east-1.amazonaws.com/api/v1/roles,context=6e8567e0b4adb68d:6e8567e0b4adb68d:0:1#You can only call finish() on a span once.

every span need to be close by calling finish(),seems call more than one time.
can u paste ur code, lets check for it?

Nothing special about the code. I was just playing around with the code example in the README and it's similar to the one below:

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import {JaegerInterceptor} from '@chankamlam/nest-jaeger'
async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  const config = {
    serviceName: 'service1-nest',
    sampler: {
        type: "const",
        param: 1
    },
    reporter: {
        collectorEndpoint: "http://localhost:14268/api/traces"
    },
};                                             // required
const options = { baggagePrefix: "-Johua-" };  // optional,you can let options={}

Could it be somehow related to this? opentracing-contrib/javascript-express#16

Nothing special about the code. I was just playing around with the code example in the README and it's similar to the one below:

import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import {JaegerInterceptor} from '@chankamlam/nest-jaeger'
async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  const config = {
    serviceName: 'service1-nest',
    sampler: {
        type: "const",
        param: 1
    },
    reporter: {
        collectorEndpoint: "http://localhost:14268/api/traces"
    },
};                                             // required
const options = { baggagePrefix: "-Johua-" };  // optional,you can let options={}

the code what u show is just about Configuration before use it, it should be the problem about use it.

[1]if u do not open a new span under master span which auto create by any requests , do not have to call span.finish()
because package had auto called the finish() method for u, lets look at the source code below:

return next.handle().pipe(
  tap(() => {
    // handle respose callback
    if (this.res_cb) {
      this.res_cb(req, res);
    }
    //mark default tag of response
    req.jaeger.setTag("response.state", res.statusCode || UNKNOW);
    req.jaeger.setTag("response.result", res.statusMessage || UNKNOW);
    req.jaeger.finish();
    ///////////////////////////////////////////////////
  })
);

[2] if u manually create new span which meant u need to call finish(),lets look at the code below

const childrenSpan = req.jaeger.create('childrenSpan') // default as children span under master span
childrenSpan.log("xxxxxx","xxxxxxxx")
childrenSpan.setTag("error",true)
childrenSpan.finish().                 // if did not call finish() that will have no record send to collector of jaeger
  • source code of the createSpan method below:
        // create new span under master span
        createSpan: (name, parent) => {
          const parentObj = parent
            ? { childOf: parent }
            : { childOf: this.span };
          if (!this.tracer) return;
          return this.tracer.startSpan(name, parentObj);
        },

Could it be somehow related to this? opentracing-contrib/javascript-express#16

his question is about using express to integrate with jaeger, this package is about nest-jaeger.
u can use this package which is about express integration with jaeger =>express-jaeger

I use the event of response as the code below:

    // auto finish for master span
    res.once("finish", () => {
      //mark default tag of response
      req.jaeger.setTag("response.state", res.statusCode || UNKNOW);
      req.jaeger.setTag("response.result", res.statusMessage || UNKNOW);
      req.jaeger.finish()
    });