javascript-express icon indicating copy to clipboard operation
javascript-express copied to clipboard

Add ability to set custom tags

Open brandondoran opened this issue 7 years ago • 3 comments

The tags currently added are great and I think they are the basic ones that you'd want to include in pretty much any express app. However, my opentracing tracer (DataDog) has some additional, required custom tags. Sure, I could write an additional middleware to add them but it would be nice if this middleware had the ability to do it.

My initial thought is just adding an tags option, which is an object:

const tags = {
  type: 'web',
  env: 'production'
};
middleware({tracer: tracer, tags })(req, res, next);

Perhaps it should be customTags to differentiate from the built-in tags?

It also might be nice to support a function, in case you want to have request specific tags:

function tags(req) {
  return {
    'http.request_id': req.id
  };
};

Any thoughts on this feature? If you think it's something the project would want to support, I could put together a PR.

brandondoran avatar Apr 06 '18 17:04 brandondoran

That sounds good to me. Perhaps some kind span decorator function that would allow you to set tags or other attributes. The instrumentation for grpc uses something like this: https://godoc.org/github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc#SpanDecorator

I'd be ok with passing tags in, being able to set them with via a function, or a mix of the approaches.

rnburn avatar Apr 06 '18 18:04 rnburn

I'm curious if any progress was made on this, I would also love the ability to add extra tags to our express spans.

binhtho avatar Feb 23 '21 21:02 binhtho

+1

AndrejGajdos avatar Dec 22 '22 12:12 AndrejGajdos