Skip to content

Commit 691c0db

Browse files
committed
alternate api for handling hooks
1 parent 5b2adc7 commit 691c0db

File tree

7 files changed

+20
-21
lines changed

7 files changed

+20
-21
lines changed

packages/datadog-plugin-apollo/src/gateway/execute.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ class ApolloGatewayExecutePlugin extends ApolloBasePlugin {
66
static operation = 'execute'
77
static prefix = 'tracing:apm:apollo:gateway:execute'
88

9-
asyncStart (ctx) {
9+
onAsyncStart (ctx) {
1010
const span = ctx?.currentStore?.span
11-
this.config.hooks.execute(span, ctx)
1211

13-
return super.asyncStart(ctx)
12+
if (!span) return
13+
14+
this.config.hooks.execute(span, ctx)
1415
}
1516
}
1617

packages/datadog-plugin-apollo/src/gateway/fetch.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,9 @@ class ApolloGatewayFetchPlugin extends ApolloBasePlugin {
3030
return ctx.currentStore
3131
}
3232

33-
asyncStart (ctx) {
33+
onAsyncStart (ctx) {
3434
const span = ctx?.currentStore?.span
3535
this.config.hooks.fetch(span, ctx)
36-
37-
return super.asyncStart(ctx)
3836
}
3937
}
4038

packages/datadog-plugin-apollo/src/gateway/plan.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ class ApolloGatewayPlanPlugin extends ApolloBasePlugin {
66
static operation = 'plan'
77
static prefix = 'tracing:apm:apollo:gateway:plan'
88

9-
asyncStart (ctx) {
9+
onEnd (ctx) {
1010
const span = ctx?.currentStore?.span
11-
this.config.hooks.plan(span, ctx)
1211

13-
return super.asyncStart(ctx)
12+
if (!span) return
13+
14+
this.config.hooks.plan(span, ctx)
1415
}
1516
}
1617

packages/datadog-plugin-apollo/src/gateway/postprocessing.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ class ApolloGatewayPostProcessingPlugin extends ApolloBasePlugin {
66
static operation = 'postprocessing'
77
static prefix = 'tracing:apm:apollo:gateway:postprocessing'
88

9-
asyncStart (ctx) {
9+
onAsyncStart (ctx) {
1010
const span = ctx?.currentStore?.span
1111
this.config.hooks.postprocessing(span, ctx)
12-
13-
return super.asyncStart(ctx)
1412
}
1513
}
1614

packages/datadog-plugin-apollo/src/gateway/request.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class ApolloGatewayRequestPlugin extends ApolloBasePlugin {
5252
return ctx.currentStore
5353
}
5454

55-
asyncStart (ctx) {
55+
onAsyncStart (ctx) {
5656
const errors = ctx?.result?.errors
5757
// apollo gateway catches certain errors and returns them in the result object
5858
// we want to capture these errors as spans
@@ -62,8 +62,6 @@ class ApolloGatewayRequestPlugin extends ApolloBasePlugin {
6262

6363
const span = ctx?.currentStore?.span
6464
this.config.hooks.request(span, ctx)
65-
66-
return super.asyncStart(ctx)
6765
}
6866
}
6967

packages/datadog-plugin-apollo/src/gateway/validate.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ class ApolloGatewayValidatePlugin extends ApolloBasePlugin {
66
static operation = 'validate'
77
static prefix = 'tracing:apm:apollo:gateway:validate'
88

9-
end (ctx) {
9+
onEnd (ctx) {
1010
const result = ctx.result
11-
const span = ctx.currentStore?.span
11+
const span = ctx?.currentStore?.span
1212

1313
if (!span) return
1414

@@ -17,8 +17,6 @@ class ApolloGatewayValidatePlugin extends ApolloBasePlugin {
1717
}
1818

1919
this.config.hooks.validate(span, ctx)
20-
21-
super.end(ctx)
2220
}
2321
}
2422

packages/dd-trace/src/plugins/apollo.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,21 @@ class ApolloBasePlugin extends TracingPlugin {
2727
}
2828

2929
end (ctx) {
30-
// Only synchronous operations would have `result` or `error` on `end`.
3130
if (!ctx.hasOwnProperty('result') && !ctx.hasOwnProperty('error')) return
31+
this.onEnd(ctx)
3232
ctx?.currentStore?.span?.finish()
3333
}
3434

3535
asyncStart (ctx) {
36-
ctx?.currentStore?.span.finish()
36+
this.onAsyncStart(ctx)
37+
ctx?.currentStore?.span?.finish()
3738
return ctx.parentStore
3839
}
3940

41+
onEnd (ctx) {}
42+
43+
onAsyncStart (ctx) {}
44+
4045
getServiceName () {
4146
return this.serviceName({
4247
id: `${this.constructor.id}.${this.constructor.operation}`,

0 commit comments

Comments
 (0)