Skip to content

Commit

Permalink
fix(headers): extract headers parameter (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
voslartomas authored and DanielMSchmidt committed May 9, 2019
1 parent e2b1273 commit 4e731d6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@
"author": "Daniel Schmidt <[email protected]>",
"license": "MIT",
"peerDependencies": {
"apollo-server-env": "< 2.4.5",
"graphql": "0.10.x - 14.x.x",
"opentracing": "*"
"apollo-server-env": "*",
"graphql": "0.10.x - 14.2.x",
"opentracing": "*",
"apollo-server": "^2.4.8"
},
"dependencies": {
"graphql-extensions": "^0.6.0"
Expand Down
20 changes: 19 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,34 @@ export default class OpentracingExtension<TContext extends SpanContext>
this.onFieldResolve = onFieldResolve;
}

mapToObj(inputMap: Map<string, any>) {
let obj: { [key: string]: string } = {};

inputMap.forEach(function(value, key){
obj[key] = value
});

return obj;
}

requestDidStart(infos: RequestStart) {
if (!this.shouldTraceRequest(infos)) {
return;
}

let headers
let tmpHeaders = infos.request && infos.request.headers as unknown as Map<string, any>
if (tmpHeaders && typeof tmpHeaders.get === 'function') {
headers = this.mapToObj(tmpHeaders)
} else {
headers = tmpHeaders
}

const externalSpan =
infos.request && infos.request.headers
? this.serverTracer.extract(
opentracing.FORMAT_HTTP_HEADERS,
infos.request.headers
headers
)
: undefined;

Expand Down

0 comments on commit 4e731d6

Please sign in to comment.