Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions packages/gateway/src/opentelemetry/setup.ts
Original file line number Diff line number Diff line change
@@ -1 +1,42 @@
import {
hiveTracingSetup as _hiveTracingSetup,
openTelemetrySetup as _openTelemetrySetup,
ATTR_SERVICE_NAME,
ATTR_SERVICE_VERSION,
OpentelemetrySetupOptions,
} from '@graphql-hive/plugin-opentelemetry/setup';
import { resourceFromAttributes } from '@opentelemetry/resources';

Check failure on line 8 in packages/gateway/src/opentelemetry/setup.ts

View workflow job for this annotation

GitHub Actions / Lint

'@opentelemetry/resources' should be listed in the project's dependencies. Run 'npm i -S @opentelemetry/resources' to add it

export * from '@graphql-hive/plugin-opentelemetry/setup';

export const openTelemetrySetup: typeof _openTelemetrySetup = (options) => {
return _openTelemetrySetup({
...options,
resource: createGatewayResource(options),
});
};

export const hiveTracingSetup: typeof _hiveTracingSetup = (options) => {
return _hiveTracingSetup({
...options,
resource: createGatewayResource(options),
});
};

function createGatewayResource(
options: Pick<OpentelemetrySetupOptions, 'resource'>,
): OpentelemetrySetupOptions['resource'] {
if (!options.resource) {
return {
serviceName: 'hive-gateway',
serviceVersion: globalThis.__OTEL_PLUGIN_VERSION__ ?? 'unknown',
Copy link
Preview

Copilot AI Sep 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a typo in the JSDoc comment above. 'an simple object' should be 'a simple object'.

Copilot uses AI. Check for mistakes.

};
} else if (!('serviceName' in options.resource)) {
return resourceFromAttributes({
[ATTR_SERVICE_NAME]: 'hive-gateway',
[ATTR_SERVICE_VERSION]: globalThis.__OTEL_PLUGIN_VERSION__ ?? 'unknown',
}).merge(options.resource);
} else {
return options.resource;
}
}
28 changes: 24 additions & 4 deletions packages/plugins/opentelemetry/src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ type SamplingOptions =
samplingRate?: number;
};

type OpentelemetrySetupOptions = TracingOptions &
export type OpentelemetrySetupOptions = TracingOptions &
SamplingOptions & {
/**
* The Resource that will be used to create the Trace Provider.
Expand Down Expand Up @@ -303,6 +303,11 @@ export type HiveTracingOptions = { target?: string } & (
export function hiveTracingSetup(
config: HiveTracingOptions & {
contextManager: ContextManager | null;
/**
* The Resource that will be used to create the Trace Provider.
* Can be either a Resource instance, or an simple object with service name and version
*/
resource?: Resource | { serviceName: string; serviceVersion: string };
log?: Logger;
},
) {
Expand Down Expand Up @@ -331,12 +336,27 @@ export function hiveTracingSetup(
logAttributes['batching'] = config.batching;
}

let resource = resourceFromAttributes({
'hive.target_id': config.target,
});

if (config.resource) {
if ('serviceName' in config.resource) {
resource = resource.merge(
resourceFromAttributes({
[ATTR_SERVICE_NAME]: config.resource.serviceName,
[ATTR_SERVICE_VERSION]: config.resource.serviceVersion,
}),
);
} else {
resource = resource.merge(config.resource);
}
}

openTelemetrySetup({
log,
contextManager: config.contextManager,
resource: resourceFromAttributes({
'hive.target_id': config.target,
}),
resource: resource,
Copy link
Preview

Copilot AI Sep 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable assignment resource: resource can be simplified to just resource using ES6 shorthand property notation.

Suggested change
resource: resource,
resource,

Copilot uses AI. Check for mistakes.

traces: {
processors: [
new HiveTracingSpanProcessor(config as HiveTracingSpanProcessorOptions),
Expand Down
Loading