federation icon indicating copy to clipboard operation
federation copied to clipboard

opentelemetry: rename `service` to `gateway.service`

Open marchenko1985 opened this issue 3 years ago • 0 comments

If we rename service to something like gateway.service here

return tracer.startActiveSpan(OpenTelemetrySpanNames.FETCH, {attributes:{service:fetch.serviceName}}, async span => {

we may use this attribute in span metrics processors of collectors to monitor the whole ecosystem (just imagine dashboards where you have gateway and underlying services) aka

image

Why we need this change:

  • service itself is a well-known span attribute, so trying to add it one more time in processor makes no sence
  • idiomatic naming is something like http.host, http.status, also in apollo there is already everything prefixed with gateway.

Alternative: if for some reason this one may break something, we can just add one more attribute with gateway.service name and the same value

Workaround: not ideal but seems to be working, we are going to extend opentelemetry exporter, and before sending traces just add such an attribute

class MyExporter extends OTLPTraceExporter {
  export(items, resultCallback) {
    for(let i = 0; i < items.length; i++) {
      if (items[i]['name'] && items[i]['name'] === 'gateway.fetch' && items[i]['attributes'] && items[i]['attributes']['service']) {
        items[i]['attributes']['gateway.service'] = items[i]['attributes']['service']
      }
    }
    super.export(items,resultCallback)
  }
}

marchenko1985 avatar Jun 29 '22 07:06 marchenko1985