-
Notifications
You must be signed in to change notification settings - Fork 1
Generalize setupOptionOtel as an independent runtime #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Ryan Zhu (underthestars-zhy)
merged 9 commits into
main
from
felix/eng-2270-developer-logs-v4-clean-complete-traces-before-clickhouse
Aug 12, 2026
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
87c533a
feat: generalize the isolated option runtime
gtxy27 df04413
fix: protect standard trace context propagation
gtxy27 12ca47d
test: verify independent option resources
gtxy27 48ad4db
docs: keep option runtime introduction together
gtxy27 55434a5
fix: align option instrumentation scope
gtxy27 cbefed8
fix: namespace option context key
gtxy27 98f655b
fix: reject malformed trace header names
gtxy27 a2e3179
refactor: rename `setupOptionOtel` to `createIsolatedOtel`
underthestars-zhy efff421
refactor(version): derive PHOTON_OTEL_VERSION from package.json
underthestars-zhy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| --- | ||
| title: "Isolated runtime" | ||
| description: "Run a second explicit trace and log pipeline without replacing the main OpenTelemetry runtime." | ||
| --- | ||
|
|
||
| `createIsolatedOtel()` creates an independent instance-level trace and log | ||
| runtime: | ||
|
|
||
| ```ts | ||
| import { createIsolatedOtel } from "@photon-ai/otel"; | ||
|
|
||
| const isolated = createIsolatedOtel({ | ||
| endpoint: "https://audit-collector.example.com", | ||
| serviceName: "audit-service", | ||
| serviceVersion: "1.2.3", | ||
| traceparentHeader: "x-audit-traceparent", | ||
| }); | ||
| ``` | ||
|
|
||
| The isolated runtime owns a separate `BasicTracerProvider`, `LoggerProvider`, | ||
| processors, exporters, and async context. It does not register any global | ||
| provider or context manager, patch fetch, configure metrics, or change the | ||
| main runtime. | ||
|
|
||
| Unlike `setupOtel()`, which is an idempotent process-wide singleton, this is a | ||
| plain factory: every call returns a new independent runtime that the caller owns | ||
| and shuts down. | ||
|
|
||
| It creates a separate Resource from `serviceName`, `serviceVersion`, and | ||
| `resourceAttributes` — the same identity options `setupOtel()` takes. It neither | ||
| copies metadata from the main runtime nor requires the main runtime to exist, | ||
| and it does not add `deployment.environment`; pass that through | ||
| `resourceAttributes` if your queries need it. | ||
|
|
||
| ## Explicit spans and logs | ||
|
|
||
| ```ts | ||
| const logger = isolated.createLogger("example.audit"); | ||
|
|
||
| await isolated.withSpan( | ||
| "report.generate", | ||
| { "app.entity.id": entityId }, | ||
| async () => { | ||
| logger.emit({ | ||
| body: "starting report generation", | ||
| eventName: "audit.message", | ||
| }); | ||
| } | ||
| ); | ||
| ``` | ||
|
|
||
| Success leaves the Span status `UNSET`. If the callback throws, the runtime | ||
| records a standard exception, marks the Span `ERROR`, ends it, and rethrows the | ||
| same value. Export and processor failures do not replace the business result. | ||
|
|
||
| The lower-level logger accepts OpenTelemetry `LogRecord` fields. A domain SDK | ||
| should normally wrap it and define its own message/severity contract. | ||
|
|
||
| ## Propagation | ||
|
|
||
| The handle exposes `capture()`, `inject()`, `extract()`, and `run()` through | ||
| `isolated.propagation`. They operate only on this runtime's async context | ||
| and use the configured `traceparentHeader`. Its value uses W3C Trace Context | ||
| encoding; the standard main `traceparent` remains untouched. | ||
|
|
||
| ## Shutdown | ||
|
|
||
| Shut down the instance runtime during application shutdown: | ||
|
|
||
| ```ts | ||
| await isolated.shutdown(); | ||
| ``` | ||
|
|
||
| Shutdown disables only this runtime's async context and providers. |
This file was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.