@@ -125,7 +125,7 @@ type BaseOptions = {
125125 * The Resource that will be used to create the Trace Provider.
126126 * Can be either a Resource instance, or an simple object with service name and version
127127 */
128- resource ?: Resource | { serviceName : string ; serviceVersion : string } ;
128+ resource ?: Resource | { serviceName : string ; serviceVersion ? : string } ;
129129 /**
130130 * The Context Manager to be used to track OTEL Context.
131131 * If possible, use `AsyncLocalStorageContextManager` from `@opentelemetry/context-async-hooks`.
@@ -244,21 +244,7 @@ export function openTelemetrySetup(options: OpentelemetrySetupOptions) {
244244 logAttributes [ 'console' ] = true ;
245245 }
246246
247- const resource = createResource (
248- resourceFromAttributes ( {
249- [ ATTR_SERVICE_NAME ] :
250- getEnvStr ( 'OTEL_SERVICE_NAME' ) ||
251- '@graphql-hive/plugin-opentelemetry' ,
252- [ ATTR_SERVICE_VERSION ] :
253- getEnvStr ( 'OTEL_SERVICE_VERSION' ) ||
254- globalThis . __OTEL_PLUGIN_VERSION__ ||
255- 'unknown' ,
256- [ 'hive.gateway.version' ] : globalThis . __VERSION__ ,
257- [ 'hive.otel.version' ] :
258- globalThis . __OTEL_PLUGIN_VERSION__ || 'unknown' ,
259- } ) ,
260- options . resource ,
261- ) ;
247+ const resource = createResource ( options ) ;
262248
263249 logAttributes [ 'resource' ] = resource . attributes ;
264250 logAttributes [ 'sampling' ] = options . sampler
@@ -311,6 +297,7 @@ export type HiveTracingOptions = { target?: string } & (
311297 accessToken ?: string ;
312298 batching ?: BufferConfig ;
313299 processor ?: never ;
300+ /** @default 'https://api.graphql-hive.com/otel/v1/traces' */
314301 endpoint ?: string ;
315302 }
316303 | {
@@ -338,40 +325,48 @@ export function hiveTracingSetup(options: HiveTracingSetupOptions) {
338325 target : options . target ,
339326 } ;
340327
341- if ( ! options . processor ) {
328+ let processorOptions : HiveTracingSpanProcessorOptions ;
329+ if ( options . processor ) {
330+ processorOptions = { processor : options . processor } ;
331+ } else {
342332 options . accessToken ??=
343333 getEnvStr ( 'HIVE_TRACING_ACCESS_TOKEN' ) ?? getEnvStr ( 'HIVE_ACCESS_TOKEN' ) ;
344-
345334 if ( ! options . accessToken ) {
346335 throw new Error (
347- 'You must specify the Hive Registry `accessToken`. Either provide `accessToken` option or `HIVE_ACCESS_TOKEN`/`HIVE_TRACE_ACCESS_TOKEN` environment variable.' ,
336+ 'You must specify the Hive Registry access token. Either provide the "accessToken" option or "HIVE_ACCESS_TOKEN"/"HIVE_TRACE_ACCESS_TOKEN" environment variable.' ,
337+ ) ;
338+ }
339+
340+ options . endpoint ??=
341+ getEnvStr ( 'HIVE_TRACING_ENDPOINT' ) ??
342+ 'https://api.graphql-hive.com/otel/v1/traces' ;
343+ if ( ! options . endpoint ) {
344+ throw new Error (
345+ 'You must specify the Hive Tracing endpoint. Either provide the "endpoint" option or the "HIVE_TRACING_ENDPOINT" environment variable.' ,
348346 ) ;
349347 }
350348
349+ processorOptions = {
350+ target : options . target ,
351+ accessToken : options . accessToken ,
352+ endpoint : options . endpoint ,
353+ batching : options . batching ,
354+ } ;
355+
351356 logAttributes [ 'endpoint' ] = options . endpoint ;
352357 logAttributes [ 'batching' ] = options . batching ;
353358 }
354359
355360 openTelemetrySetup ( {
356361 ...options ,
357362 log,
358- resource : createResource (
363+ resource : createResource ( options ) . merge (
359364 resourceFromAttributes ( {
360365 'hive.target_id' : options . target ,
361- [ ATTR_SERVICE_NAME ] : getEnvStr ( 'OTEL_SERVICE_NAME' ) || 'hive-gateway' ,
362- [ ATTR_SERVICE_VERSION ] :
363- getEnvStr ( 'OTEL_SERVICE_VERSION' ) ||
364- globalThis . __OTEL_PLUGIN_VERSION__ ||
365- 'unknown' ,
366366 } ) ,
367- options . resource ,
368367 ) ,
369368 traces : {
370- processors : [
371- new HiveTracingSpanProcessor (
372- options as HiveTracingSpanProcessorOptions ,
373- ) ,
374- ] ,
369+ processors : [ new HiveTracingSpanProcessor ( processorOptions ) ] ,
375370 spanLimits : options . spanLimits ,
376371 console : options . console ,
377372 } ,
@@ -400,24 +395,27 @@ function resolveBatchingConfig(
400395 }
401396}
402397
403- function createResource (
404- baseResource : Resource ,
405- userResource ?: OpentelemetrySetupOptions [ 'resource' ] ,
406- ) : Resource {
407- if ( ! userResource ) {
408- return baseResource ;
409- }
410-
411- if ( 'serviceName' in userResource ) {
412- return baseResource . merge (
413- resourceFromAttributes ( {
414- [ ATTR_SERVICE_NAME ] : userResource . serviceName ,
415- [ ATTR_SERVICE_VERSION ] : userResource . serviceVersion ,
416- } ) ,
417- ) ;
398+ function createResource ( opts : Pick < OpentelemetrySetupOptions , 'resource' > ) {
399+ const resourceObj =
400+ opts . resource && 'serviceName' in opts . resource ? opts . resource : null ;
401+
402+ let resource = resourceFromAttributes ( {
403+ [ ATTR_SERVICE_NAME ] :
404+ resourceObj ?. serviceName ||
405+ getEnvStr ( 'OTEL_SERVICE_NAME' ) ||
406+ 'hive-gateway' ,
407+ [ ATTR_SERVICE_VERSION ] :
408+ resourceObj ?. serviceVersion ||
409+ getEnvStr ( 'OTEL_SERVICE_VERSION' ) ||
410+ globalThis . __VERSION__ ||
411+ 'unknown' ,
412+ [ 'hive.otel.version' ] : globalThis . __OTEL_PLUGIN_VERSION__ || 'unknown' ,
413+ } ) ;
414+ if ( opts . resource && 'attributes' in opts . resource ) {
415+ // opts.resource is a Resource
416+ resource = resource . merge ( opts . resource ) ;
418417 }
419-
420- return baseResource . merge ( userResource ) ;
418+ return resource ;
421419}
422420
423421/**
0 commit comments