federation
federation copied to clipboard
opentelemetry: rename `service` to `gateway.service`
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
Why we need this change:
-
serviceitself 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 withgateway.
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)
}
}