From 4e731d6136e853d79f149851d003429746481c38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Vosla=C5=99?= Date: Thu, 9 May 2019 12:04:27 +0200 Subject: [PATCH] fix(headers): extract headers parameter (#218) --- package.json | 7 ++++--- src/index.ts | 20 +++++++++++++++++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index b78f94b0..aa9fff86 100644 --- a/package.json +++ b/package.json @@ -32,9 +32,10 @@ "author": "Daniel Schmidt ", "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" diff --git a/src/index.ts b/src/index.ts index ae32717a..4d5fb2d7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -104,16 +104,34 @@ export default class OpentracingExtension this.onFieldResolve = onFieldResolve; } + mapToObj(inputMap: Map) { + 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 + 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;