elastic / elastic/apm-agent-nodejs

Transiting traceparent over custom transports

Open
#978 22 comments 3 reactions 0 assignees View on GitHub
agent-nodejs
Dominant language
JavaScript
Stars
594
Forks
244
Avg merge
1d 8h
Merged PRs (30d)
16

Description

I'm implementing [grpc-node](https://github.com/grpc/grpc-node) support (specifically the `grpc` npm package) with the new [addPatch](https://www.elastic.co/guide/en/apm/agent/nodejs/current/agent-api.html#apm-add-patch) agent API.

I had guessed (incorrectly!) that if GRPC wasn't supported for `apm-agent-nodejs` that it wasn't supported for any Elastic APM agent. I've found, however, that at least `apm-agent-go` [has GRPC support](https://github.com/elastic/apm-agent-go/tree/master/module/apmgrpc), so I want to make sure that my implementation is fully compatible for distributed tracing.

I have three questions:

1) What is the officially supported way to obtain the correct APM context in `apm-agent-nodejs` to transit between services for distributed tracing?

I was looking at some of the existing code (link below) and am weary of using the `_context` property of `Span` found therein. Does the leading underscore mean this is not a public interface? If it is a private interface, is there an alternative way to obtain this information?

https://github.com/elastic/apm-agent-nodejs/blob/853c9ddde1ce2d671e3d478e103edeeac5f29539/lib/instrumentation/http-shared.js#L122-L130

2) Why are S3 hosts blacklisted in the `http-shared` module?

https://github.com/elastic/apm-agent-nodejs/blob/853c9ddde1ce2d671e3d478e103edeeac5f29539/lib/instrumentation/http-shared.js#L181-L183

3) When I transit this APM context from GRPC client to GRPC server, what is the correct way to do so?

Before I learned that GRPC was supported by some Elastic APM agents, I was just going to stuff the string representation of the context into some of the call's metadata, but looking more closely at `apm-agent-go` (disclaimer: I do not know golang) it looks like the GRPC implementation depends on the header name from the HTTP implementation:

https://github.com/elastic/apm-agent-go/blob/master/module/apmgrpc/server.go#L97-L98

Which means that when this value changes in a future version of the agent pending W3C standard freeze, the GRPC metadata key will also be changed.

https://github.com/elastic/apm-agent-go/blob/master/module/apmhttp/traceheaders.go#L31-L36

So, how can I make sure that my implementation for `node-grpc` is similarly responsive to this change?

Any other advice or pointers would be greatly appreciated!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.