WIP: Swap Workiva opentelemetry for Dartastic OpenTelemetry - #1
Draft
michaelbushe wants to merge 1 commit into
Draft
WIP: Swap Workiva opentelemetry for Dartastic OpenTelemetry#1michaelbushe wants to merge 1 commit into
michaelbushe wants to merge 1 commit into
Conversation
Experimental swap of the OpenTelemetry implementation in
packages/genkit from Workiva's `opentelemetry: ^0.18.10` to
Dartastic's `dartastic_opentelemetry: ^1.1.0-beta.4`. Motivation:
Dartastic ships web support (Flutter web, dart2js, dart2wasm),
OTLP/HTTP-JSON wire format on every signal natively, and
late-binding global proxies that make module-load tracer capture
correct across `OTel.initialize` — the three things Genkit Dart
needs to ship its dev UI integration on web.
## Code conversion
- `packages/genkit/lib/src/o11y/instrumentation.dart`:
- `api.globalTracerProvider.getTracer('genkit-dart')` →
`OTel.tracerProvider().getTracer('genkit-dart')`. The returned
Tracer is a `LateBindingTracer` proxy whose identity is stable
across `OTel.initialize`; module-load capture stays correct.
- `api.Attribute.fromString(k, v)` list-building → single
`OTel.attributesFromMap({...})` call.
- `span.setAttribute(api.Attribute.fromString(k, v))` →
`span.setStringAttribute<String>(k, v)`.
- `span.setStatus(api.StatusCode.error, msg)` →
`span.setStatus(SpanStatusCode.Error, msg)`.
- `api.contextWithSpan(api.Context.current, span)` →
`Context.current.withSpan(span)`.
- Genkit's Zone-keyed (`#api.context`) context propagation
preserved — the original mechanism is independent of the OTel
package and just stores a `Context` value.
- `packages/genkit/lib/src/o11y/telemetry/exporter_impl.dart`:
- Hand-rolled `CollectorHttpExporter` (JSON-encoded OTLP over
HTTP) removed entirely. Replaced with Dartastic's built-in
`OtlpHttpSpanExporter` configured with
`OtlpHttpProtocol.httpJson`, which generates proto3-JSON OTLP
via `request.toProto3Json()` on the generated protobuf classes
— no hand-rolled marshaling in Dartastic.
- `setupExporter` now checks `OTel.isInitialized`:
- If host already initialized OTel (typical when Genkit runs
inside an app that owns its observability stack), the dev UI
exporter is added alongside existing processors via
`OTel.tracerProvider().addSpanProcessor(processor)`. Both
exporters fire on each span.
- Otherwise, bootstraps OTel itself with the dev UI exporter as
the sole span processor. Fire-and-forget initialize — by the
time the next span is created, init has completed. The
late-binding proxy held by `runInNewSpan`'s `_tracer`
module-load capture survives this transition.
- Endpoint passed as `$baseUrl/api/otlp/v1/traces` so Dartastic
leaves the path alone (the SDK appends `/v1/traces` only when
the configured endpoint doesn't already end with it).
## Tests
- `packages/genkit/test/test_util.dart`: `TextExporter` converted
to Dartastic's `SpanExporter` interface (async export/forceFlush/
shutdown returning Future<void>).
- `packages/genkit/test/core/action_test.dart`: replaced
`sdk.TracerProviderBase` + `api.registerGlobalTracerProvider`
with `OTel.tracerProvider().addSpanProcessor(processor)` on the
late-binding proxy. `span.attributes.get(k)` →
`span.attributes.getString(k)` (Dartastic's typed accessors).
- `packages/genkit/test/o11y/instrumentation_test.dart`: setUp
now `await OTel.reset()` between tests for clean state; uses
`SimpleSpanProcessor` directly and asserts
`childSpan.spanContext.parentSpanId == parentSpan.spanContext.spanId`.
- `packages/genkit/test/o11y/otlp_http_exporter_test.dart` removed
— it tested Genkit's now-deleted `CollectorHttpExporter`. The
equivalent coverage for `OtlpHttpSpanExporter` lives upstream in
Dartastic's own test suite.
## Pubspec
- `packages/genkit/pubspec.yaml`: `opentelemetry: ^0.18.10` →
`dartastic_opentelemetry: ^1.1.0-beta.4`.
- Workspace-root `pubspec.yaml` adds `dependency_overrides` with
git refs to in-flight Dartastic branches:
- `dartastic_opentelemetry`: MindfulSoftwareLLC/dartastic_opentelemetry
@ `feat/late-binding-proxies` — the late-binding-proxies SDK
work (`OTel.tracer()` captured at module load survives
`OTel.initialize`) plus OTLP/HTTP-JSON support and web
compatibility.
- `dartastic_opentelemetry_api`: MindfulSoftwareLLC/dartastic_opentelemetry_api
@ `feat/noop-default-factory` — the spec-aligned noop default
factory that the SDK's proxies rely on.
Remove these overrides once both packages publish their pending
betas to pub.dev.
## Validation
All 252 Genkit tests pass with the Dartastic backend.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Experimental swap of the OpenTelemetry implementation in
packages/genkitfrom Workiva'sopentelemetry: ^0.18.10to Dartastic OpenTelemetrydartastic_opentelemetry: ^1.1.0-beta.4.final _tracer = OTel.tracerProvider().getTracer('genkit-dart')captured at module load stays correct after the host callsOTel.initialize(matches Java'sGlobalOpenTelemetry.get()semantics).What changed
packages/genkit/lib/src/o11y/instrumentation.dartapi.globalTracerProvider.getTracer(...)→OTel.tracerProvider().getTracer(...)(late-binding proxy)OTel.attributesFromMap({...})callsetStringAttribute<String>)api.StatusCode.error→SpanStatusCode.Errorapi.contextWithSpan(api.Context.current, span)→Context.current.withSpan(span)#api.context) context propagation preserved as-ispackages/genkit/lib/src/o11y/telemetry/exporter_impl.dartCollectorHttpExporterremoved — replaced with Dartastic's built-inOtlpHttpSpanExporterconfigured withOtlpHttpProtocol.httpJson(usesrequest.toProto3Json()on the generated protobuf classes, no hand-rolled marshaling)setupExporterchecksOTel.isInitialized:addSpanProcessor— both exporters fire on each spanTests
test/test_util.dart:TextExporterported to Dartastic's asyncSpanExporterinterfacetest/core/action_test.dart: tracer-provider setup migrated to the proxy;span.attributes.get(k)→span.attributes.getString(k)(Dartastic's typed accessors)test/o11y/instrumentation_test.dart:setUpnowawait OTel.reset()between tests; asserts viaspanContext.parentSpanId/spanContext.spanIdtest/o11y/otlp_http_exporter_test.dartremoved — it tested Genkit's now-deletedCollectorHttpExporter. The equivalent coverage forOtlpHttpSpanExporterlives upstream in Dartastic's own test suite.Pubspec
packages/genkit/pubspec.yaml: dependency swap.Workspace-root
pubspec.yaml:dependency_overrideswith git refs to in-flight Dartastic branches:MindfulSoftwareLLC/dartastic_opentelemetry@feat/late-binding-proxiesMindfulSoftwareLLC/dartastic_opentelemetry_api@feat/noop-default-factoryRemove these overrides once both packages publish their pending betas to pub.dev.
Test plan
dart testinpackages/genkit— 252/252 pass$baseUrl/api/otlp/v1/tracesdart test -p chromeagainst a Flutter-web testapp to confirm web compatibility (the original motivation)/v1/traces(spec-compliant OTLP path) or whether it needs to keep accepting the bare/api/otlppath — currently we send to/v1/tracesso Dartastic doesn't append it twiceStatus: WIP / draft
Filed against the fork's
mainfor experimentation. Promote togenkit-ai/genkit-dartonce the Dartastic API/SDK betas are published to pub.dev (thedependency_overridesblock disappears at that point) and the dev UI compatibility item above is settled.🤖 Generated with Claude Code