@editframe/elements 0.26.3-beta.0 → 0.26.4-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/package.json +2 -2
  2. package/scripts/build-css.js +3 -3
  3. package/tsdown.config.ts +1 -1
  4. package/src/elements/ContextProxiesController.ts +0 -124
  5. package/src/elements/CrossUpdateController.ts +0 -22
  6. package/src/elements/EFAudio.browsertest.ts +0 -706
  7. package/src/elements/EFAudio.ts +0 -56
  8. package/src/elements/EFCaptions.browsertest.ts +0 -1960
  9. package/src/elements/EFCaptions.ts +0 -823
  10. package/src/elements/EFImage.browsertest.ts +0 -120
  11. package/src/elements/EFImage.ts +0 -113
  12. package/src/elements/EFMedia/AssetIdMediaEngine.test.ts +0 -224
  13. package/src/elements/EFMedia/AssetIdMediaEngine.ts +0 -110
  14. package/src/elements/EFMedia/AssetMediaEngine.browsertest.ts +0 -140
  15. package/src/elements/EFMedia/AssetMediaEngine.ts +0 -385
  16. package/src/elements/EFMedia/BaseMediaEngine.browsertest.ts +0 -400
  17. package/src/elements/EFMedia/BaseMediaEngine.ts +0 -505
  18. package/src/elements/EFMedia/BufferedSeekingInput.browsertest.ts +0 -386
  19. package/src/elements/EFMedia/BufferedSeekingInput.ts +0 -430
  20. package/src/elements/EFMedia/JitMediaEngine.browsertest.ts +0 -226
  21. package/src/elements/EFMedia/JitMediaEngine.ts +0 -256
  22. package/src/elements/EFMedia/audioTasks/makeAudioBufferTask.browsertest.ts +0 -679
  23. package/src/elements/EFMedia/audioTasks/makeAudioBufferTask.ts +0 -117
  24. package/src/elements/EFMedia/audioTasks/makeAudioFrequencyAnalysisTask.ts +0 -246
  25. package/src/elements/EFMedia/audioTasks/makeAudioInitSegmentFetchTask.browsertest.ts +0 -59
  26. package/src/elements/EFMedia/audioTasks/makeAudioInitSegmentFetchTask.ts +0 -27
  27. package/src/elements/EFMedia/audioTasks/makeAudioInputTask.browsertest.ts +0 -55
  28. package/src/elements/EFMedia/audioTasks/makeAudioInputTask.ts +0 -53
  29. package/src/elements/EFMedia/audioTasks/makeAudioSeekTask.chunkboundary.regression.browsertest.ts +0 -207
  30. package/src/elements/EFMedia/audioTasks/makeAudioSeekTask.ts +0 -72
  31. package/src/elements/EFMedia/audioTasks/makeAudioSegmentFetchTask.ts +0 -32
  32. package/src/elements/EFMedia/audioTasks/makeAudioSegmentIdTask.ts +0 -29
  33. package/src/elements/EFMedia/audioTasks/makeAudioTasksVideoOnly.browsertest.ts +0 -95
  34. package/src/elements/EFMedia/audioTasks/makeAudioTimeDomainAnalysisTask.ts +0 -184
  35. package/src/elements/EFMedia/shared/AudioSpanUtils.ts +0 -129
  36. package/src/elements/EFMedia/shared/BufferUtils.ts +0 -342
  37. package/src/elements/EFMedia/shared/GlobalInputCache.ts +0 -77
  38. package/src/elements/EFMedia/shared/MediaTaskUtils.ts +0 -44
  39. package/src/elements/EFMedia/shared/PrecisionUtils.ts +0 -46
  40. package/src/elements/EFMedia/shared/RenditionHelpers.browsertest.ts +0 -246
  41. package/src/elements/EFMedia/shared/RenditionHelpers.ts +0 -56
  42. package/src/elements/EFMedia/shared/ThumbnailExtractor.ts +0 -227
  43. package/src/elements/EFMedia/tasks/makeMediaEngineTask.browsertest.ts +0 -167
  44. package/src/elements/EFMedia/tasks/makeMediaEngineTask.ts +0 -88
  45. package/src/elements/EFMedia/videoTasks/MainVideoInputCache.ts +0 -76
  46. package/src/elements/EFMedia/videoTasks/ScrubInputCache.ts +0 -61
  47. package/src/elements/EFMedia/videoTasks/makeScrubVideoBufferTask.ts +0 -114
  48. package/src/elements/EFMedia/videoTasks/makeScrubVideoInitSegmentFetchTask.ts +0 -35
  49. package/src/elements/EFMedia/videoTasks/makeScrubVideoInputTask.ts +0 -52
  50. package/src/elements/EFMedia/videoTasks/makeScrubVideoSeekTask.ts +0 -124
  51. package/src/elements/EFMedia/videoTasks/makeScrubVideoSegmentFetchTask.ts +0 -44
  52. package/src/elements/EFMedia/videoTasks/makeScrubVideoSegmentIdTask.ts +0 -32
  53. package/src/elements/EFMedia/videoTasks/makeUnifiedVideoSeekTask.ts +0 -370
  54. package/src/elements/EFMedia/videoTasks/makeVideoBufferTask.ts +0 -109
  55. package/src/elements/EFMedia.browsertest.ts +0 -872
  56. package/src/elements/EFMedia.ts +0 -341
  57. package/src/elements/EFSourceMixin.ts +0 -60
  58. package/src/elements/EFSurface.browsertest.ts +0 -151
  59. package/src/elements/EFSurface.ts +0 -142
  60. package/src/elements/EFTemporal.browsertest.ts +0 -215
  61. package/src/elements/EFTemporal.ts +0 -800
  62. package/src/elements/EFThumbnailStrip.browsertest.ts +0 -585
  63. package/src/elements/EFThumbnailStrip.media-engine.browsertest.ts +0 -714
  64. package/src/elements/EFThumbnailStrip.ts +0 -906
  65. package/src/elements/EFTimegroup.browsertest.ts +0 -934
  66. package/src/elements/EFTimegroup.ts +0 -882
  67. package/src/elements/EFVideo.browsertest.ts +0 -1482
  68. package/src/elements/EFVideo.ts +0 -564
  69. package/src/elements/EFWaveform.ts +0 -547
  70. package/src/elements/FetchContext.browsertest.ts +0 -401
  71. package/src/elements/FetchMixin.ts +0 -38
  72. package/src/elements/SampleBuffer.ts +0 -94
  73. package/src/elements/TargetController.browsertest.ts +0 -230
  74. package/src/elements/TargetController.ts +0 -224
  75. package/src/elements/TimegroupController.ts +0 -26
  76. package/src/elements/durationConverter.ts +0 -35
  77. package/src/elements/parseTimeToMs.ts +0 -9
  78. package/src/elements/printTaskStatus.ts +0 -16
  79. package/src/elements/renderTemporalAudio.ts +0 -108
  80. package/src/elements/updateAnimations.browsertest.ts +0 -1884
  81. package/src/elements/updateAnimations.ts +0 -217
  82. package/src/elements/util.ts +0 -24
  83. package/src/gui/ContextMixin.browsertest.ts +0 -860
  84. package/src/gui/ContextMixin.ts +0 -562
  85. package/src/gui/Controllable.browsertest.ts +0 -258
  86. package/src/gui/Controllable.ts +0 -41
  87. package/src/gui/EFConfiguration.ts +0 -40
  88. package/src/gui/EFControls.browsertest.ts +0 -389
  89. package/src/gui/EFControls.ts +0 -195
  90. package/src/gui/EFDial.browsertest.ts +0 -84
  91. package/src/gui/EFDial.ts +0 -172
  92. package/src/gui/EFFilmstrip.browsertest.ts +0 -712
  93. package/src/gui/EFFilmstrip.ts +0 -1349
  94. package/src/gui/EFFitScale.ts +0 -152
  95. package/src/gui/EFFocusOverlay.ts +0 -79
  96. package/src/gui/EFPause.browsertest.ts +0 -202
  97. package/src/gui/EFPause.ts +0 -73
  98. package/src/gui/EFPlay.browsertest.ts +0 -202
  99. package/src/gui/EFPlay.ts +0 -73
  100. package/src/gui/EFPreview.ts +0 -74
  101. package/src/gui/EFResizableBox.browsertest.ts +0 -79
  102. package/src/gui/EFResizableBox.ts +0 -898
  103. package/src/gui/EFScrubber.ts +0 -151
  104. package/src/gui/EFTimeDisplay.browsertest.ts +0 -237
  105. package/src/gui/EFTimeDisplay.ts +0 -55
  106. package/src/gui/EFToggleLoop.ts +0 -35
  107. package/src/gui/EFTogglePlay.ts +0 -70
  108. package/src/gui/EFWorkbench.ts +0 -115
  109. package/src/gui/PlaybackController.ts +0 -527
  110. package/src/gui/TWMixin.css +0 -6
  111. package/src/gui/TWMixin.ts +0 -61
  112. package/src/gui/TargetOrContextMixin.ts +0 -185
  113. package/src/gui/currentTimeContext.ts +0 -5
  114. package/src/gui/durationContext.ts +0 -3
  115. package/src/gui/efContext.ts +0 -6
  116. package/src/gui/fetchContext.ts +0 -5
  117. package/src/gui/focusContext.ts +0 -7
  118. package/src/gui/focusedElementContext.ts +0 -5
  119. package/src/gui/playingContext.ts +0 -5
  120. package/src/otel/BridgeSpanExporter.ts +0 -150
  121. package/src/otel/setupBrowserTracing.ts +0 -73
  122. package/src/otel/tracingHelpers.ts +0 -251
  123. package/src/transcoding/cache/RequestDeduplicator.test.ts +0 -170
  124. package/src/transcoding/cache/RequestDeduplicator.ts +0 -65
  125. package/src/transcoding/cache/URLTokenDeduplicator.test.ts +0 -182
  126. package/src/transcoding/cache/URLTokenDeduplicator.ts +0 -101
  127. package/src/transcoding/types/index.ts +0 -312
  128. package/src/transcoding/utils/MediaUtils.ts +0 -63
  129. package/src/transcoding/utils/UrlGenerator.ts +0 -68
  130. package/src/transcoding/utils/constants.ts +0 -36
  131. package/src/utils/LRUCache.test.ts +0 -274
  132. package/src/utils/LRUCache.ts +0 -696
@@ -1,185 +0,0 @@
1
- import { type Context, consume } from "@lit/context";
2
- import type { LitElement } from "lit";
3
- import { property, state } from "lit/decorators.js";
4
- import { isEFTemporal } from "../elements/EFTemporal.js";
5
- import { TargetController } from "../elements/TargetController.js";
6
- import { type ControllableInterface, isControllable } from "./Controllable.js";
7
- import { currentTimeContext } from "./currentTimeContext.js";
8
- import { durationContext } from "./durationContext.js";
9
- import { loopContext, playingContext } from "./playingContext.js";
10
-
11
- type Constructor<T = {}> = new (...args: any[]) => T;
12
-
13
- class ContextRequestEvent extends Event {
14
- context: Context<any, any>;
15
- contextTarget: Element;
16
- callback: (value: any, unsubscribe: () => void) => void;
17
- subscribe: boolean;
18
-
19
- constructor(
20
- context: Context<any, any>,
21
- contextTarget: Element,
22
- callback: (value: any, unsubscribe: () => void) => void,
23
- subscribe: boolean,
24
- ) {
25
- super("context-request", { bubbles: true, composed: true });
26
- this.context = context;
27
- this.contextTarget = contextTarget;
28
- this.callback = callback;
29
- this.subscribe = subscribe ?? false;
30
- }
31
- }
32
-
33
- export function TargetOrContextMixin<T extends Constructor<LitElement>>(
34
- superClass: T,
35
- contextToProxy: Context<any, any>,
36
- ) {
37
- class TargetOrContextClass extends superClass {
38
- @property({ type: String })
39
- target = "";
40
-
41
- @state()
42
- targetElement: ControllableInterface | null = null;
43
-
44
- // @ts-expect-error contextToProxy is generic but provides ControllableInterface at runtime
45
- @consume({ context: contextToProxy, subscribe: true })
46
- contextFromParent: ControllableInterface | null = null;
47
-
48
- #targetController?: TargetController;
49
- #contextUnsubscribe?: () => void;
50
- #contextRequestHandler?: (event: Event) => void;
51
- #additionalContextUnsubscribes = new Map<Context<any, any>, () => void>();
52
-
53
- get effectiveContext(): ControllableInterface | null {
54
- return this.targetElement ?? this.contextFromParent;
55
- }
56
-
57
- connectedCallback() {
58
- super.connectedCallback();
59
- if (this.target) {
60
- this.#targetController = new TargetController(
61
- this as any as LitElement & {
62
- targetElement: Element | null;
63
- target: string;
64
- },
65
- );
66
- }
67
-
68
- // Intercept context-request events and redirect them to targetElement
69
- this.#contextRequestHandler = (event: Event) => {
70
- if (this.targetElement && event.type === "context-request") {
71
- event.stopPropagation();
72
- this.targetElement.dispatchEvent(
73
- new (event.constructor as any)(event.type, event),
74
- );
75
- }
76
- };
77
- this.addEventListener(
78
- "context-request",
79
- this.#contextRequestHandler,
80
- true,
81
- );
82
- }
83
-
84
- #subscribeToTargetContext() {
85
- if (!this.targetElement) return;
86
-
87
- this.#contextUnsubscribe?.();
88
-
89
- // Unsubscribe from all additional contexts
90
- for (const unsubscribe of this.#additionalContextUnsubscribes.values()) {
91
- unsubscribe();
92
- }
93
- this.#additionalContextUnsubscribes.clear();
94
-
95
- // Subscribe to efContext
96
- const event = new ContextRequestEvent(
97
- contextToProxy,
98
- this,
99
- (value, unsubscribe) => {
100
- (this as any).contextFromParent = value;
101
- this.#contextUnsubscribe = unsubscribe;
102
- },
103
- true,
104
- );
105
- this.targetElement.dispatchEvent(event);
106
-
107
- // Subscribe to additional contexts that controls commonly need
108
- const additionalContexts: Array<[Context<any, any>, string]> = [
109
- [playingContext, "playing"],
110
- [loopContext, "loop"],
111
- [currentTimeContext, "currentTimeMs"],
112
- [durationContext, "durationMs"],
113
- ];
114
-
115
- for (const [context, propertyName] of additionalContexts) {
116
- const contextEvent = new ContextRequestEvent(
117
- context,
118
- this,
119
- (value, unsubscribe) => {
120
- // Update the control's property if it exists
121
- if (propertyName in this) {
122
- (this as any)[propertyName] = value;
123
- }
124
- this.#additionalContextUnsubscribes.set(context, unsubscribe);
125
- },
126
- true,
127
- );
128
- this.targetElement.dispatchEvent(contextEvent);
129
- }
130
- }
131
-
132
- updated(changedProperties: Map<string | number | symbol, unknown>): void {
133
- super.updated?.(changedProperties);
134
-
135
- if (changedProperties.has("targetElement") && this.targetElement) {
136
- if (
137
- isEFTemporal(this.targetElement) &&
138
- !isControllable(this.targetElement)
139
- ) {
140
- console.warn(
141
- "Control element is targeting a non-root temporal element without playbackController. " +
142
- "Controls can only target root temporal elements (not nested within a timegroup). " +
143
- "Target element:",
144
- this.targetElement,
145
- );
146
- }
147
- this.#subscribeToTargetContext();
148
- }
149
-
150
- if (changedProperties.has("target")) {
151
- if (this.target && !this.#targetController) {
152
- this.#targetController = new TargetController(
153
- this as any as LitElement & {
154
- targetElement: Element | null;
155
- target: string;
156
- },
157
- );
158
- }
159
- }
160
- }
161
-
162
- disconnectedCallback() {
163
- super.disconnectedCallback();
164
- this.#contextUnsubscribe?.();
165
- for (const unsubscribe of this.#additionalContextUnsubscribes.values()) {
166
- unsubscribe();
167
- }
168
- this.#additionalContextUnsubscribes.clear();
169
- if (this.#contextRequestHandler) {
170
- this.removeEventListener(
171
- "context-request",
172
- this.#contextRequestHandler,
173
- true,
174
- );
175
- }
176
- }
177
- }
178
-
179
- return TargetOrContextClass as Constructor<{
180
- target: string;
181
- targetElement: ControllableInterface | null;
182
- effectiveContext: ControllableInterface | null;
183
- }> &
184
- T;
185
- }
@@ -1,5 +0,0 @@
1
- import { createContext } from "@lit/context";
2
-
3
- export const currentTimeContext = createContext<number>(
4
- Symbol("currentTimeMs"),
5
- );
@@ -1,3 +0,0 @@
1
- import { createContext } from "@lit/context";
2
-
3
- export const durationContext = createContext<number>(Symbol("durationMs"));
@@ -1,6 +0,0 @@
1
- import { createContext } from "@lit/context";
2
- import type { ControllableInterface } from "./Controllable.js";
3
-
4
- export const efContext = createContext<ControllableInterface | null>(
5
- Symbol("efContext"),
6
- );
@@ -1,5 +0,0 @@
1
- import { createContext } from "@lit/context";
2
-
3
- export const fetchContext = createContext<
4
- (url: string, init?: RequestInit) => Promise<Response>
5
- >(Symbol("fetchContext"));
@@ -1,7 +0,0 @@
1
- import { createContext } from "@lit/context";
2
-
3
- export interface FocusContext {
4
- focusedElement: HTMLElement | null;
5
- }
6
-
7
- export const focusContext = createContext<FocusContext>(Symbol("focusContext"));
@@ -1,5 +0,0 @@
1
- import { createContext } from "@lit/context";
2
-
3
- export const focusedElementContext = createContext<HTMLElement | undefined>(
4
- Symbol("focusedElement"),
5
- );
@@ -1,5 +0,0 @@
1
- import { createContext } from "@lit/context";
2
-
3
- export const playingContext = createContext<boolean>(Symbol("playingContext"));
4
-
5
- export const loopContext = createContext<boolean>(Symbol("loopContext"));
@@ -1,150 +0,0 @@
1
- import { type ExportResult, ExportResultCode } from "@opentelemetry/core";
2
- import type { ReadableSpan, SpanExporter } from "@opentelemetry/sdk-trace-base";
3
-
4
- function toHex(value: unknown): string {
5
- if (typeof value === "string") return value;
6
- if (Array.isArray(value)) {
7
- return value
8
- .map((b) => {
9
- const byte = typeof b === "number" ? b : 0;
10
- return byte.toString(16).padStart(2, "0");
11
- })
12
- .join("");
13
- }
14
- if (ArrayBuffer.isView(value)) {
15
- return Array.from(value as Uint8Array)
16
- .map((b) => b.toString(16).padStart(2, "0"))
17
- .join("");
18
- }
19
- return String(value);
20
- }
21
-
22
- interface OtlpAttributeValue {
23
- stringValue?: string;
24
- intValue?: number;
25
- doubleValue?: number;
26
- boolValue?: boolean;
27
- arrayValue?: { values: OtlpAttributeValue[] };
28
- }
29
-
30
- function convertAttribute(value: unknown): OtlpAttributeValue {
31
- if (typeof value === "string") return { stringValue: value };
32
- if (typeof value === "number")
33
- return Number.isInteger(value)
34
- ? { intValue: value }
35
- : { doubleValue: value };
36
- if (typeof value === "boolean") return { boolValue: value };
37
- if (Array.isArray(value))
38
- return { arrayValue: { values: value.map(convertAttribute) } };
39
- return { stringValue: String(value) };
40
- }
41
-
42
- interface BridgeWithSpanExport {
43
- exportSpans?: (endpoint: string, payload: string) => void;
44
- }
45
-
46
- export class BridgeSpanExporter implements SpanExporter {
47
- private bridge: BridgeWithSpanExport;
48
- private endpoint: string;
49
-
50
- constructor(bridge: BridgeWithSpanExport, endpoint: string) {
51
- this.bridge = bridge;
52
- this.endpoint = endpoint;
53
- }
54
-
55
- export(
56
- spans: ReadableSpan[],
57
- resultCallback: (result: ExportResult) => void,
58
- ): void {
59
- if (!this.bridge?.exportSpans) {
60
- resultCallback({ code: ExportResultCode.FAILED });
61
- return;
62
- }
63
-
64
- try {
65
- const otlpPayload = {
66
- resourceSpans: [
67
- {
68
- resource: {
69
- attributes: Object.entries(
70
- spans[0]?.resource?.attributes || {},
71
- ).map(([key, value]) => ({
72
- key,
73
- value: convertAttribute(value),
74
- })),
75
- },
76
- scopeSpans: [
77
- {
78
- scope: {
79
- name: "telecine-browser",
80
- version: "1.0.0",
81
- },
82
- spans: spans.map((span) => {
83
- const ctx = span.spanContext();
84
- return {
85
- traceId: toHex(ctx.traceId),
86
- spanId: toHex(ctx.spanId),
87
- parentSpanId: span.parentSpanId
88
- ? toHex(span.parentSpanId)
89
- : undefined,
90
- name: span.name,
91
- kind: span.kind,
92
- startTimeUnixNano: String(
93
- span.startTime[0] * 1_000_000_000 + span.startTime[1],
94
- ),
95
- endTimeUnixNano: String(
96
- span.endTime[0] * 1_000_000_000 + span.endTime[1],
97
- ),
98
- attributes: Object.entries(span.attributes).map(
99
- ([key, value]) => ({
100
- key,
101
- value: convertAttribute(value),
102
- }),
103
- ),
104
- status: span.status,
105
- events: span.events.map((event) => ({
106
- timeUnixNano: String(
107
- event.time[0] * 1_000_000_000 + event.time[1],
108
- ),
109
- name: event.name,
110
- attributes: Object.entries(event.attributes || {}).map(
111
- ([key, value]) => ({
112
- key,
113
- value: convertAttribute(value),
114
- }),
115
- ),
116
- })),
117
- links: span.links.map((link) => ({
118
- traceId: toHex(link.context.traceId),
119
- spanId: toHex(link.context.spanId),
120
- attributes: Object.entries(link.attributes || {}).map(
121
- ([key, value]) => ({
122
- key,
123
- value: convertAttribute(value),
124
- }),
125
- ),
126
- })),
127
- };
128
- }),
129
- },
130
- ],
131
- },
132
- ],
133
- };
134
-
135
- const serializedPayload = JSON.stringify(otlpPayload);
136
-
137
- this.bridge.exportSpans(this.endpoint, serializedPayload);
138
- resultCallback({ code: ExportResultCode.SUCCESS });
139
- } catch (error) {
140
- resultCallback({
141
- code: ExportResultCode.FAILED,
142
- error: error instanceof Error ? error : new Error(String(error)),
143
- });
144
- }
145
- }
146
-
147
- shutdown(): Promise<void> {
148
- return Promise.resolve();
149
- }
150
- }
@@ -1,73 +0,0 @@
1
- import { Resource } from "@opentelemetry/resources";
2
- import {
3
- BatchSpanProcessor,
4
- SimpleSpanProcessor,
5
- } from "@opentelemetry/sdk-trace-base";
6
- import { WebTracerProvider } from "@opentelemetry/sdk-trace-web";
7
- import { ATTR_SERVICE_NAME } from "@opentelemetry/semantic-conventions";
8
- import { BridgeSpanExporter } from "./BridgeSpanExporter.js";
9
-
10
- let isInitialized = false;
11
- let provider: WebTracerProvider | null = null;
12
-
13
- interface BridgeWithSpanExport {
14
- exportSpans?: (endpoint: string, payload: string) => void;
15
- }
16
-
17
- export interface BrowserTracingConfig {
18
- otelEndpoint: string;
19
- serviceName?: string;
20
- bridge?: BridgeWithSpanExport;
21
- useBatching?: boolean;
22
- }
23
-
24
- export async function setupBrowserTracing(
25
- config: BrowserTracingConfig,
26
- ): Promise<void> {
27
- if (isInitialized) {
28
- return;
29
- }
30
-
31
- try {
32
- if (!config.bridge) {
33
- throw new Error("Bridge is required for browser tracing");
34
- }
35
-
36
- const exporter = new BridgeSpanExporter(config.bridge, config.otelEndpoint);
37
-
38
- let spanProcessor: BatchSpanProcessor | SimpleSpanProcessor;
39
- if (config.useBatching) {
40
- spanProcessor = new BatchSpanProcessor(exporter, {
41
- maxQueueSize: 100,
42
- maxExportBatchSize: 10,
43
- scheduledDelayMillis: 500,
44
- });
45
- } else {
46
- spanProcessor = new SimpleSpanProcessor(exporter);
47
- }
48
-
49
- provider = new WebTracerProvider({
50
- resource: new Resource({
51
- [ATTR_SERVICE_NAME]: config.serviceName || "telecine-browser",
52
- }),
53
- spanProcessors: [spanProcessor],
54
- });
55
-
56
- // Dynamically import ZoneContextManager only when tracing is enabled
57
- // This prevents zone.js from being loaded for users who don't need tracing
58
- const { ZoneContextManager } = await import("@opentelemetry/context-zone");
59
-
60
- provider.register({
61
- contextManager: new ZoneContextManager(),
62
- });
63
-
64
- isInitialized = true;
65
- } catch (error) {
66
- console.error("Failed to initialize browser tracing:", error);
67
- throw error;
68
- }
69
- }
70
-
71
- export function isBrowserTracingInitialized(): boolean {
72
- return isInitialized;
73
- }
@@ -1,251 +0,0 @@
1
- import {
2
- type Context,
3
- context,
4
- propagation,
5
- type Span,
6
- trace,
7
- } from "@opentelemetry/api";
8
-
9
- export type TraceContext = Record<string, string>;
10
-
11
- /**
12
- * Global flag to enable/disable tracing.
13
- * When false, all tracing functions become no-ops for zero overhead.
14
- */
15
- let tracingEnabled = false;
16
-
17
- /**
18
- * Enable tracing globally. Call this during initialization if tracing is requested.
19
- */
20
- export function enableTracing(): void {
21
- tracingEnabled = true;
22
- }
23
-
24
- /**
25
- * Check if tracing is currently enabled.
26
- */
27
- export function isTracingEnabled(): boolean {
28
- return tracingEnabled;
29
- }
30
-
31
- /**
32
- * Frame-local span storage for rendering.
33
- * Since rendering is single-threaded and sequential (one frame at a time),
34
- * we store the active frame span directly and use it as parent for orphaned spans.
35
- */
36
- let currentFrameSpan: Span | undefined;
37
-
38
- /**
39
- * Set the current frame's span. Call this when starting a frame render.
40
- * All spans created during this frame will use this as parent if
41
- * Zone.js doesn't provide one via context.active()
42
- */
43
- export function setCurrentFrameSpan(span: Span): void {
44
- currentFrameSpan = span;
45
- }
46
-
47
- /**
48
- * Clear the current frame span. Call this when a frame completes.
49
- */
50
- export function clearCurrentFrameSpan(): void {
51
- currentFrameSpan = undefined;
52
- }
53
-
54
- export function extractParentContext(traceContext?: TraceContext): Context {
55
- if (!traceContext) {
56
- return context.active();
57
- }
58
-
59
- try {
60
- return propagation.extract(context.active(), traceContext);
61
- } catch (_error) {
62
- return context.active();
63
- }
64
- }
65
-
66
- /**
67
- * Get the active span's context to pass to child operations
68
- * Use this when calling functions that create child spans
69
- */
70
- export function getActiveContext(): Context {
71
- return context.active();
72
- }
73
-
74
- /**
75
- * Wrapper that passes span context explicitly to the function
76
- * Use this for operations that need to store or propagate context across boundaries
77
- */
78
- export async function withSpanAndContext<T>(
79
- name: string,
80
- attributes: Record<string, string | number | boolean> | undefined,
81
- parentContext: Context | undefined,
82
- fn: (span: Span, activeContext: Context) => Promise<T>,
83
- ): Promise<T> {
84
- // No-op if tracing is disabled
85
- if (!tracingEnabled) {
86
- // Create a minimal no-op span for compatibility
87
- const noopSpan = trace.getTracer("telecine-browser").startSpan(name);
88
- const ctx = parentContext || context.active();
89
- const result = await fn(noopSpan, ctx);
90
- noopSpan.end();
91
- return result;
92
- }
93
-
94
- const tracer = trace.getTracer("telecine-browser");
95
-
96
- // Same context resolution as withSpan
97
- let ctx: Context;
98
-
99
- if (parentContext) {
100
- ctx = parentContext;
101
- } else {
102
- const activeContext = context.active();
103
- const activeSpan = trace.getSpan(activeContext);
104
-
105
- if (activeSpan?.isRecording?.()) {
106
- ctx = activeContext;
107
- } else if (currentFrameSpan) {
108
- ctx = trace.setSpan(context.active(), currentFrameSpan);
109
- } else {
110
- ctx = activeContext;
111
- }
112
- }
113
-
114
- const span = tracer.startSpan(
115
- name,
116
- {
117
- attributes,
118
- },
119
- ctx,
120
- );
121
-
122
- // Create context with this span as active
123
- const spanContext = trace.setSpan(ctx, span);
124
-
125
- try {
126
- // Pass the spanContext explicitly to the function
127
- const result = await context.with(spanContext, async () => {
128
- return fn(span, spanContext);
129
- });
130
- span.end();
131
- return result;
132
- } catch (error) {
133
- span.recordException(error as Error);
134
- span.end();
135
- throw error;
136
- }
137
- }
138
-
139
- export function createSpan(
140
- name: string,
141
- attributes?: Record<string, string | number | boolean>,
142
- parentContext?: Context,
143
- ): Span {
144
- const tracer = trace.getTracer("telecine-browser");
145
- const ctx = parentContext || context.active();
146
-
147
- return context.with(ctx, () => {
148
- const span = tracer.startSpan(name);
149
-
150
- if (attributes) {
151
- span.setAttributes(attributes);
152
- }
153
-
154
- return span;
155
- });
156
- }
157
-
158
- export async function withSpan<T>(
159
- name: string,
160
- attributes: Record<string, string | number | boolean> | undefined,
161
- parentContext: Context | undefined,
162
- fn: (span: Span) => Promise<T>,
163
- ): Promise<T> {
164
- // No-op if tracing is disabled
165
- if (!tracingEnabled) {
166
- // Create a minimal no-op span for compatibility
167
- const noopSpan = trace.getTracer("telecine-browser").startSpan(name);
168
- const result = await fn(noopSpan);
169
- noopSpan.end();
170
- return result;
171
- }
172
-
173
- const tracer = trace.getTracer("telecine-browser");
174
-
175
- // Context resolution priority:
176
- // 1. Explicit parentContext (if provided)
177
- // 2. context.active() from Zone.js (if it has a valid span)
178
- // 3. Create context from currentFrameSpan (fallback for Lit Task boundaries)
179
- let ctx: Context;
180
-
181
- if (parentContext) {
182
- ctx = parentContext;
183
- } else {
184
- const activeContext = context.active();
185
- const activeSpan = trace.getSpan(activeContext);
186
-
187
- // Try to use context.active() if it has a real span
188
- if (activeSpan?.isRecording?.()) {
189
- ctx = activeContext;
190
- } else if (currentFrameSpan) {
191
- // Create context from the stored frame span
192
- ctx = trace.setSpan(context.active(), currentFrameSpan);
193
- } else {
194
- ctx = activeContext;
195
- }
196
- }
197
-
198
- // Start span with explicit parent
199
- const span = tracer.startSpan(
200
- name,
201
- {
202
- attributes,
203
- },
204
- ctx,
205
- );
206
-
207
- // Create context with this span as active
208
- const spanContext = trace.setSpan(ctx, span);
209
-
210
- try {
211
- // Execute function with span context
212
- const result = await context.with(spanContext, async () => {
213
- return fn(span);
214
- });
215
- span.end();
216
- return result;
217
- } catch (error) {
218
- span.recordException(error as Error);
219
- span.end();
220
- throw error;
221
- }
222
- }
223
-
224
- export function withSpanSync<T>(
225
- name: string,
226
- attributes: Record<string, string | number | boolean> | undefined,
227
- parentContext: Context | undefined,
228
- fn: (span: Span) => T,
229
- ): T {
230
- // No-op if tracing is disabled
231
- if (!tracingEnabled) {
232
- // Create a minimal no-op span for compatibility
233
- const noopSpan = trace.getTracer("telecine-browser").startSpan(name);
234
- const result = fn(noopSpan);
235
- noopSpan.end();
236
- return result;
237
- }
238
-
239
- const span = createSpan(name, attributes, parentContext);
240
- const ctx = parentContext || context.active();
241
-
242
- try {
243
- const result = context.with(trace.setSpan(ctx, span), () => fn(span));
244
- span.end();
245
- return result;
246
- } catch (error) {
247
- span.recordException(error as Error);
248
- span.end();
249
- throw error;
250
- }
251
- }