Comments (17)
@nadilas few weeks ago i did https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-propagator-jaeger , u can try to use it
from apollo-opentracing.
I am unsure how apollo federation works, does it allow you to write the resolvers for the services yourself?
from apollo-opentracing.
@DanielMSchmidt There is a good blog post about it here: https://blog.apollographql.com/apollo-federation-f260cf525d21
It has a gateway layer which gets the GraphQL queries and then the gateway knows which portion of the query to send to which microservice. So, it splits the GQL query to multiple services where resolvers are written and then gets the aggregated response from all the services back to the gateway.
from apollo-opentracing.
@tvvignesh Hello, looking for the same thing, did u manage to find solution?
from apollo-opentracing.
@DotSpy None out of the box as of now since Federation is pretty new. We have to manually instrument the services using open tracing and trace it using jaeger.
from apollo-opentracing.
@tvvignesh i stuck at gateway, because i'm not used to JS, i would really appreciate if u can provide some pieces of code for it
Update: ohh my mistake thought u implemented it, i will try to do it, if smth will be done will let u know
from apollo-opentracing.
I was able to get this to work by using a custom datasource and overriding the willSendRequest() call.
On the willSendRequest()
method, you don't have the info parameter with the request, so I was able to set it on the Context object on the ApolloServer. I took the approach of getting the root span and returning that in the context so that it's always available and then in the willSendRequest()
, I created a child span and applied the headers to the request parameter so that downstream Apollo servers get the headers set too.
from apollo-opentracing.
For now u can use just https://github.com/open-telemetry/opentelemetry-js/tree/master/packages/opentelemetry-node
from apollo-opentracing.
@sysadmind can you share your willSendRequest
implementation?
from apollo-opentracing.
@nadilas i tried this solution, to use it u need not only custom GraphQLDataSource but also change sources of apollo server. For now i suggest u just to include opentelemetry-js
from apollo-opentracing.
@DotSpy thanks. I may oversimplify this, but wouldn’t setting the span Id in the outgoing header and setting that as a parent id on the root span solve the stitching issue?
from apollo-opentracing.
@nadilas yeap, it will, but to do so you need receive parent id via context as @sysadmind told
from apollo-opentracing.
Here is the willSendRequest that I was able to use. Note that you need to implement the context
willSendRequest({ request, context }) {
const tracer = opentracing.globalTracer();
const networkSpan = tracer.startSpan('federated request', {
childOf: context.rootSpan ? context.rootSpan : undefined,
});
let injectHeaders = {};
tracer.inject(networkSpan, opentracing.FORMAT_HTTP_HEADERS, injectHeaders);
for (const [key, value] of Object.entries(injectHeaders)) {
request.http.headers.set(key, value);
}
return () => {
networkSpan.finish();
};
}
from apollo-opentracing.
thanks for sharing @sysadmind. Let me check if I got this right.
You are using opentracing.globalTracer()
because you have used opentracing.initGlobalTracer()
with your own tracer implementation?
By "implement the context" you probably something tracer.extract
in the context: ({ req }) => {}
of the apollo-server I assume?
Edit: I just realized you meant in the gateway and not within the federated service - as it already extracts incoming headers.
One more thing, are you sure rootSpan
is the correct name? I'm using https://github.com/DanielMSchmidt/zipkin-javascript-opentracing as the implementation and it looks like it's using childOf
: https://github.com/DanielMSchmidt/zipkin-javascript-opentracing/blob/948858890c1a833d69edd90ca44b87e6ed1ac184/src/index.js#L96
from apollo-opentracing.
- Yes I have used
opentracing.initGlobalTracer(myTracer)
so that I can reference it withopentracing.globalTracer()
instead of having to pass it through other means. This function also returns a noop tracer if not previously set, so things like tests should still work even without initializing a tracer. - Implementing the context: correct, here's a simple version:
context: ({ req }) => {
var externalSpan =
req && req.headers
? tracer.extract(opentracing.FORMAT_HTTP_HEADERS, req.headers)
: undefined;
return {
rootSpan: externalSpan,
};
},
- Federation: Yes this all happens in the gateway so that the downstream federated server can extract this span
- rootSapn: I updated my above code. It was a bad copy paste. My apologies. The intent was to set the
childOf
attribute to therootSpan
from the context.
from apollo-opentracing.
Thanks great summary! Sounds about right :-)
What I still can’t figure out is, how I can attach the federated service to the span of the field which actually initiated the call to the federated service. I haven’t tested this yet, but it will attach all federated calls to the root and hence show a different (faster) timeline than what actually happens, right? I somehow fear that without info on willSendRequest we would need to hook into the fieldWillResolve and overwrite the rootSpan with the one from Info.span so we can grab that particular field.
Now the only question is, what happens in race scenarios? Maybe a map on context (url => span) would solve this, if we had the url available.
from apollo-opentracing.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
from apollo-opentracing.
Related Issues (20)
- Update peerDependencie graphql from 14.0.x to 14.x.x HOT 2
- Type error in apollo-server@^2.4.6 HOT 6
- zipkin headers not propagated HOT 2
- Extending SpanContext in TypeScript HOT 3
- Prolongate Opentracing HTTP Headers HOT 7
- How to use apollo-opentracing with graphql-yoga middlewares HOT 2
- License HOT 1
- Top level span names other than `request` HOT 4
- extensions deprecation HOT 10
- What is the point of the second tracer? HOT 2
- subscriptions HOT 6
- Action Required: Fix Renovate Configuration
- The automated release is failing 🚨 HOT 1
- How to trace errors from "didEncounterErrors"? HOT 2
- Support Apollo v3 server HOT 2
- Dependency Dashboard
- Return TraceID in graphql response HOT 1
- bug: update default to use newest apollo-server-plugin-base HOT 1
- Migrate to apollo server v4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from apollo-opentracing.