@@ -741,7 +741,6 @@ npm i dd-trace
741
741
``` ts filename="telemetry.ts"
742
742
import ddTrace from ' dd-trace'
743
743
import { openTelemetrySetup } from ' @graphql-hive/gateway/opentelemetry/setup'
744
- import { AsyncLocalStorageContextManager } from ' @opentelemetry/context-async-hooks'
745
744
746
745
const { TracerProvider } = ddTrace .init ({
747
746
// Your configuration
@@ -1866,7 +1865,7 @@ export const gatewayConfig = defineConfig({
1866
1865
traces: true ,
1867
1866
},
1868
1867
genericAuth: {
1869
- resolveUserFn : ({ context } ) => {
1868
+ resolveUserFn : (context ) => {
1870
1869
// `startActiveSpan` will rely on the current context to parent the new span correctly
1871
1870
// You can also use your own tracer instead of Hive Gateway's one.
1872
1871
return hive .tracer ! .startActiveSpan (' users.fetch' , (span ) => {
@@ -1912,7 +1911,7 @@ export const gateway = createGatewayRuntime({
1912
1911
traces: true
1913
1912
}),
1914
1913
useGenericAuth ({
1915
- resolveUserFn : ({ context } ) => {
1914
+ resolveUserFn : (context ) => {
1916
1915
// `startActiveSpan` will rely on the current context to parent the new span correctly
1917
1916
// You can also use your own tracer instead of Hive Gateway's one.
1918
1917
return hive .tracer ! .startActiveSpan (' users.fetch' , (span ) => {
@@ -1953,7 +1952,6 @@ to get the proper context.
1953
1952
import { defineConfig } from ' @graphql-hive/gateway'
1954
1953
import { openTelemetrySetup } from ' @graphql-hive/gateway/opentelemetry/setup'
1955
1954
import { hive } from ' @graphql-hive/gateway/opentelemetry/api'
1956
- import { AsyncLocalStorageContextManager } from ' @opentelemetry/context-async-hooks'
1957
1955
import { useGenericAuth } from ' @envelop/generic-auth'
1958
1956
1959
1957
openTelemetrySetup ({
@@ -1968,7 +1966,7 @@ export const gatewayConfig = defineConfig({
1968
1966
},
1969
1967
plugins : () => [
1970
1968
useGenericAuth ({
1971
- resolveUserFn : ({ context } ) => {
1969
+ resolveUserFn : (context ) => {
1972
1970
const otelCtx = hive .getActiveContext ({ context });
1973
1971
1974
1972
// Explicitly pass the parent context as the third argument.
@@ -1992,7 +1990,6 @@ import { createGatewayRuntime } from '@graphql-hive/gateway-runtime'
1992
1990
import { useOpenTelemetry } from ' @graphql-hive/plugin-opentelemetry'
1993
1991
import { hive } from ' @graphql-hive/plugin-opentelemetry/api'
1994
1992
import { openTelemetrySetup } from ' @graphql-hive/plugin-opentelemetry/setup'
1995
- import { AsyncLocalStorageContextManager } from ' @opentelemetry/context-async-hooks'
1996
1993
import { useGenericAuth } from ' @envelop/generic-auth'
1997
1994
1998
1995
openTelemetrySetup ({
@@ -2009,7 +2006,7 @@ export const gateway = createGatewayRuntime({
2009
2006
traces: true
2010
2007
}),
2011
2008
useGenericAuth ({
2012
- resolveUserFn : ({ context } ) => {
2009
+ resolveUserFn : (context ) => {
2013
2010
const otelCtx = hive .getActiveContext ({ context });
2014
2011
2015
2012
// Explicitly pass the parent context as the third argument.
@@ -2077,7 +2074,7 @@ export const gatewayConfig = defineConfig({
2077
2074
},
2078
2075
plugins : () => [
2079
2076
useGenericAuth ({
2080
- resolveUserFn : ({ context } ) => {
2077
+ resolveUserFn : (context ) => {
2081
2078
const span = trace .getActiveSpan ();
2082
2079
const user = await fetchUser (extractUserIdFromContext (context ))
2083
2080
span .setAttribute (' user.id' , user .id );
@@ -2106,7 +2103,6 @@ import { defineConfig } from '@graphql-hive/gateway'
2106
2103
import { openTelemetrySetup } from ' @graphql-hive/plugin-opentelemetry/setup'
2107
2104
// This package re-export official @opentelemetry/api package for ease of use
2108
2105
import { trace , hive } from ' @graphql-hive/plugin-opentelemetry/api'
2109
- import { AsyncLocalStorageContextManager } from ' @opentelemetry/context-async-hooks'
2110
2106
2111
2107
openTelemetrySetup ({
2112
2108
contextManager: null , // Don't register any context manager
@@ -2120,7 +2116,7 @@ export const gatewayConfig = defineConfig({
2120
2116
},
2121
2117
plugins : () => [
2122
2118
useGenericAuth ({
2123
- resolveUserFn : ({ context } ) => {
2119
+ resolveUserFn : (context ) => {
2124
2120
const user = await fetchUser (extractUserIdFromContext (context ))
2125
2121
2126
2122
const otelCtx = hive .getActiveContext ({ context })
@@ -2151,11 +2147,32 @@ You can access those spans by using `getHttpContext(request)`, `getOperationCont
2151
2147
` getExecutionRequestContext(executionRequest) ` functions from
2152
2148
` @graphql-hive/gateway/opentelemetry/api ` .
2153
2149
2154
- They are accessible under ` openTelemetry ` key of the graphql and configuration context, and on the
2155
- plugin instance if you don't have access to any of those contexts.
2150
+ They are also accessible under ` openTelemetry ` key of the graphql and configuration context, and on
2151
+ the plugin. When using the graphql context, the argument is optional and functions will return the
2152
+ current appropriate root context.
2156
2153
2157
- When using the graphql context, the argument is optional and functions will return the current
2158
- appropriate root context.
2154
+ ``` ts filename="gateway.config.ts"
2155
+ import { hive , trace } ' @graphql-hive/gateway/opentelemetry/api'
2156
+ import { defineConfig } from ' @graphql-hive/gateway'
2157
+
2158
+ export config gatewayConfig = defineConfig ({
2159
+ openTelemetry : {
2160
+ traces : true
2161
+ },
2162
+
2163
+ plugin : () => [{
2164
+ onRequest({ request }) {
2165
+ const httpSpan = trace .getSpan (hive .getHttpContext (request ))
2166
+ },
2167
+ onExecute({ context }) {
2168
+ const operationSpan = trace .getSpan (hive .getOperationContext (context ))
2169
+ },
2170
+ onSubgraphExecute({ executionRequest }) {
2171
+ const executionRequestSpan = trace .getSpan (hive .getExecutionRequestContext (executionRequest ))
2172
+ },
2173
+ }]
2174
+ })
2175
+ ```
2159
2176
2160
2177
### Troubleshooting
2161
2178
@@ -2176,7 +2193,7 @@ import { openTelemetrySetup } from '@graphql-hive/plugin-opentelemetry/setup'
2176
2193
import { AsyncLocalStorageContextManager } from ' @opentelemetry/context-async-hooks'
2177
2194
2178
2195
openTelemetrySetup ({
2179
- contextManager: new AsyncLocalStorageContextManager
2196
+ contextManager: new AsyncLocalStorageContextManager (),
2180
2197
traces: {
2181
2198
console: true
2182
2199
}
@@ -2657,6 +2674,7 @@ ignore introspection queries for all metrics prefixed by `graphql_envelop_` by s
2657
2674
</Tabs.Tab >
2658
2675
2659
2676
<Tabs.Tab >
2677
+
2660
2678
By default, all labels are enabled, but each one can be disabled to reduce cardinality:
2661
2679
2662
2680
``` ts filename="gateway.config.ts"
0 commit comments