Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 12 additions & 2 deletions genkit-tools/common/src/types/trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,16 @@ export const LinkSchema = z.object({
});

/**
* Zod schema for instrumentation library.
* Zod schema for instrumentation scope.
*/
export const InstrumentationScopeSchema = z.object({
name: z.string().readonly(),
version: z.string().optional().readonly(),
schemaUrl: z.string().optional().readonly(),
});

/**
* Zod schema for legacy instrumentation library.
*/
export const InstrumentationLibrarySchema = z.object({
name: z.string().readonly(),
Expand All @@ -118,7 +127,8 @@ export const SpanDataSchema = z
attributes: z.record(z.string(), z.unknown()),
displayName: z.string(),
links: z.array(LinkSchema).optional(),
instrumentationLibrary: InstrumentationLibrarySchema,
instrumentationLibrary: InstrumentationLibrarySchema.optional(),
instrumentationScope: InstrumentationScopeSchema.optional(),
spanKind: z.string(),
sameProcessAsParentSpan: z.object({ value: z.boolean() }).optional(),
status: SpanStatusSchema.optional(),
Expand Down
22 changes: 21 additions & 1 deletion genkit-tools/genkit-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1404,6 +1404,24 @@
],
"additionalProperties": false
},
"InstrumentationScope": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"version": {
"type": "string"
},
"schemaUrl": {
"type": "string"
}
},
"required": [
"name"
],
"additionalProperties": false
},
"Link": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -1500,6 +1518,9 @@
"instrumentationLibrary": {
"$ref": "#/$defs/InstrumentationLibrary"
},
"instrumentationScope": {
"$ref": "#/$defs/InstrumentationScope"
},
"spanKind": {
"type": "string"
},
Expand Down Expand Up @@ -1541,7 +1562,6 @@
"endTime",
"attributes",
"displayName",
"instrumentationLibrary",
"spanKind"
],
"additionalProperties": false
Expand Down
2 changes: 1 addition & 1 deletion genkit-tools/telemetry-server/src/utils/otlp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function toSpanData(span: OtlpSpan, scope: OtlpScopeSpan['scope']): SpanData {
endTime: toMillis(span.endTimeUnixNano),
displayName: span.name,
attributes,
instrumentationLibrary: {
instrumentationScope: {
name: scope.name,
version: scope.version,
},
Expand Down
6 changes: 6 additions & 0 deletions go/ai/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ type GenerationUsage struct {
TotalTokens int `json:"totalTokens,omitempty"`
}

type InstrumentationScope struct {
Name string `json:"name,omitempty"`
SchemaUrl string `json:"schemaUrl,omitempty"`
Version string `json:"version,omitempty"`
}

type Media struct {
ContentType string `json:"contentType,omitempty"`
Url string `json:"url,omitempty"`
Expand Down
12 changes: 6 additions & 6 deletions js/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
"license": "Apache-2.0",
"dependencies": {
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/context-async-hooks": "~1.25.0",
"@opentelemetry/core": "~1.25.0",
"@opentelemetry/sdk-metrics": "~1.25.0",
"@opentelemetry/sdk-node": "^0.52.0",
"@opentelemetry/sdk-trace-base": "~1.25.0",
"@opentelemetry/exporter-jaeger": "^1.25.0",
"@opentelemetry/context-async-hooks": "^2.2.0",
"@opentelemetry/core": "^2.2.0",
"@opentelemetry/sdk-metrics": "^2.2.0",
"@opentelemetry/sdk-node": "^0.208.0",
"@opentelemetry/sdk-trace-base": "^2.2.0",
"@opentelemetry/exporter-jaeger": "^2.2.0",
"@types/json-schema": "^7.0.15",
"ajv": "^8.12.0",
"ajv-formats": "^3.0.1",
Expand Down
20 changes: 10 additions & 10 deletions js/core/src/tracing/exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class TraceServerExporter implements SpanExporter {
displayName: span.name,
links: span.links,
spanKind: SpanKind[span.kind],
parentSpanId: span.parentSpanId,
parentSpanId: span.parentSpanContext?.spanId,
sameProcessAsParentSpan: { value: !span.spanContext().isRemote },
status: span.status,
timeEvents: {
Expand All @@ -85,17 +85,17 @@ export class TraceServerExporter implements SpanExporter {
})),
},
};
if (span.instrumentationLibrary !== undefined) {
spanData.instrumentationLibrary = {
name: span.instrumentationLibrary.name,
if (span.instrumentationScope !== undefined) {
spanData.instrumentationScope = {
name: span.instrumentationScope.name,
};
if (span.instrumentationLibrary.schemaUrl !== undefined) {
spanData.instrumentationLibrary.schemaUrl =
span.instrumentationLibrary.schemaUrl;
if (span.instrumentationScope.schemaUrl !== undefined) {
spanData.instrumentationScope.schemaUrl =
span.instrumentationScope.schemaUrl;
}
if (span.instrumentationLibrary.version !== undefined) {
spanData.instrumentationLibrary.version =
span.instrumentationLibrary.version;
if (span.instrumentationScope.version !== undefined) {
spanData.instrumentationScope.version =
span.instrumentationScope.version;
}
}
deleteUndefinedProps(spanData);
Expand Down
9 changes: 8 additions & 1 deletion js/core/src/tracing/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ export const InstrumentationLibrarySchema = z.object({
schemaUrl: z.string().optional().readonly(),
});

export const InstrumentationScopeSchema = z.object({
name: z.string().readonly(),
version: z.string().optional().readonly(),
schemaUrl: z.string().optional().readonly(),
});

export const SpanDataSchema = z.object({
spanId: z.string(),
traceId: z.string(),
Expand All @@ -89,7 +95,8 @@ export const SpanDataSchema = z.object({
attributes: z.record(z.string(), z.any()),
displayName: z.string(),
links: z.array(LinkSchema).optional(),
instrumentationLibrary: InstrumentationLibrarySchema,
instrumentationLibrary: InstrumentationLibrarySchema.optional(),
instrumentationScope: InstrumentationScopeSchema.optional(),
spanKind: z.string(),
sameProcessAsParentSpan: z.object({ value: z.boolean() }).optional(),
status: SpanStatusSchema.optional(),
Expand Down
2 changes: 1 addition & 1 deletion js/core/tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class TestSpanExporter implements SpanExporter {
displayName: span.name,
links: span.links,
spanKind: SpanKind[span.kind],
parentSpanId: span.parentSpanId,
parentSpanId: span.parentSpanContext?.spanId,
sameProcessAsParentSpan: { value: !span.spanContext().isRemote },
status: span.status,
timeEvents: {
Expand Down
24 changes: 12 additions & 12 deletions js/plugins/google-cloud/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@
"license": "Apache-2.0",
"dependencies": {
"@google-cloud/logging-winston": "^6.0.0",
"@google-cloud/opentelemetry-cloud-monitoring-exporter": "^0.19.0",
"@google-cloud/opentelemetry-cloud-trace-exporter": "^2.4.1",
"@google-cloud/opentelemetry-resource-util": "^2.4.0",
"@google-cloud/opentelemetry-cloud-monitoring-exporter": "^0.21.0",
"@google-cloud/opentelemetry-cloud-trace-exporter": "^3.0.0",
"@google-cloud/opentelemetry-resource-util": "^3.0.0",
"@opentelemetry/api": "^1.9.0",
"@opentelemetry/auto-instrumentations-node": "^0.49.1",
"@opentelemetry/core": "~1.25.0",
"@opentelemetry/instrumentation": "^0.52.0",
"@opentelemetry/instrumentation-pino": "^0.41.0",
"@opentelemetry/instrumentation-winston": "^0.39.0",
"@opentelemetry/resources": "~1.25.0",
"@opentelemetry/sdk-metrics": "~1.25.0",
"@opentelemetry/sdk-node": "^0.52.0",
"@opentelemetry/sdk-trace-base": "~1.25.0",
"@opentelemetry/auto-instrumentations-node": "^0.67.1",
"@opentelemetry/core": "^2.2.0",
"@opentelemetry/instrumentation": "^0.208.0",
"@opentelemetry/instrumentation-pino": "^0.55.0",
"@opentelemetry/instrumentation-winston": "^0.53.0",
"@opentelemetry/resources": "^2.2.0",
"@opentelemetry/sdk-metrics": "^2.2.0",
"@opentelemetry/sdk-node": "^0.208.0",
"@opentelemetry/sdk-trace-base": "^2.2.0",
"google-auth-library": "^9.6.3",
"node-fetch": "^3.3.2",
"winston": "^3.12.0"
Expand Down
21 changes: 12 additions & 9 deletions js/plugins/google-cloud/src/gcpOpenTelemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ import { type ExportResult } from '@opentelemetry/core';
import type { Instrumentation } from '@opentelemetry/instrumentation';
import { PinoInstrumentation } from '@opentelemetry/instrumentation-pino';
import { WinstonInstrumentation } from '@opentelemetry/instrumentation-winston';
import { Resource } from '@opentelemetry/resources';
import { Resource, resourceFromAttributes } from '@opentelemetry/resources';
import {
AggregationOption,
AggregationTemporality,
DefaultAggregation,
ExponentialHistogramAggregation,
AggregationType,
InMemoryMetricExporter,
InstrumentType,
PeriodicExportingMetricReader,
Expand Down Expand Up @@ -73,9 +73,12 @@ export class GcpOpenTelemetry {

constructor(config: GcpTelemetryConfig) {
this.config = config;
this.resource = new Resource({ type: 'global' }).merge(
new GcpDetectorSync().detect()
);

const detectedResource = new GcpDetectorSync().detect();
this.resource = resourceFromAttributes({
type: 'global',
...detectedResource.attributes,
});
}

/**
Expand Down Expand Up @@ -237,11 +240,11 @@ class MetricExporterWrapper extends MetricExporter {
});
}

selectAggregation(instrumentType: InstrumentType) {
selectAggregation(instrumentType: InstrumentType): AggregationOption {
if (instrumentType === InstrumentType.HISTOGRAM) {
return new ExponentialHistogramAggregation();
return { type: AggregationType.EXPONENTIAL_HISTOGRAM };
}
return new DefaultAggregation();
return { type: AggregationType.DEFAULT };
}

selectAggregationTemporality(instrumentType: InstrumentType) {
Expand Down
Loading
Loading