@@ -65,7 +65,7 @@ import {
65
65
setUpstreamFetchAttributes ,
66
66
setUpstreamFetchResponseAttributes ,
67
67
} from './spans' ;
68
- import { tryContextManagerSetup } from './utils' ;
68
+ import { getEnvVar , tryContextManagerSetup } from './utils' ;
69
69
70
70
type BooleanOrPredicate < TInput = never > =
71
71
| boolean
@@ -103,11 +103,18 @@ interface OpenTelemetryGatewayPluginOptionsWithInit {
103
103
*/
104
104
exporters : MaybePromise < SpanProcessor > [ ] ;
105
105
/**
106
- * Service name to use for OpenTelemetry NodeSDK resource option (default: 'Gateway').
106
+ * Service name to use for OpenTelemetry Resource option (default: 'Gateway').
107
107
*
108
108
* Does not apply when `initializeNodeSDK` is `false`.
109
109
*/
110
110
serviceName ?: string ;
111
+ /**
112
+ * Service version to use for OpenTelemetry Resource option (default: Hive Gateway version).
113
+ *
114
+ * Note: This can also be set by using `OTEL_SERVICE_VERSION` environment variable.
115
+ */
116
+ serviceVersion ?: string ;
117
+
111
118
/**
112
119
* Whether to rely on OTEL context api for span correlation.
113
120
* - `undefined` (default): the plugin will try to enable context manager if possible.
@@ -315,8 +322,11 @@ export function useOpenTelemetry(
315
322
316
323
const resource = detectResources ( ) . merge (
317
324
resourceFromAttributes ( {
318
- [ SEMRESATTRS_SERVICE_NAME ] : options . serviceName ?? 'Gateway' ,
319
- [ ATTR_SERVICE_VERSION ] : yogaVersion . promise ,
325
+ [ SEMRESATTRS_SERVICE_NAME ] :
326
+ options . serviceName ?? getEnvVar ( 'OTEL_SERVICE_NAME' , 'Gateway' ) ,
327
+ [ ATTR_SERVICE_VERSION ] :
328
+ options . serviceVersion ??
329
+ getEnvVar ( 'OTEL_SERVICE_VERSION' , yogaVersion . promise ) ,
320
330
} ) ,
321
331
) ;
322
332
0 commit comments