@superblocksteam/telemetry 2.0.83-next.1
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.
- package/LICENSE.txt +87 -0
- package/README.md +155 -0
- package/dist/browser/index.d.ts +8 -0
- package/dist/browser/index.d.ts.map +1 -0
- package/dist/browser/index.js +19 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/init.d.ts +75 -0
- package/dist/browser/init.d.ts.map +1 -0
- package/dist/browser/init.js +169 -0
- package/dist/browser/init.js.map +1 -0
- package/dist/browser/resilient-exporter.d.ts +43 -0
- package/dist/browser/resilient-exporter.d.ts.map +1 -0
- package/dist/browser/resilient-exporter.js +88 -0
- package/dist/browser/resilient-exporter.js.map +1 -0
- package/dist/common/contracts/tier2-traces.d.ts +75 -0
- package/dist/common/contracts/tier2-traces.d.ts.map +1 -0
- package/dist/common/contracts/tier2-traces.js +186 -0
- package/dist/common/contracts/tier2-traces.js.map +1 -0
- package/dist/common/deployment-type.d.ts +18 -0
- package/dist/common/deployment-type.d.ts.map +1 -0
- package/dist/common/deployment-type.js +30 -0
- package/dist/common/deployment-type.js.map +1 -0
- package/dist/common/guardrails.d.ts +116 -0
- package/dist/common/guardrails.d.ts.map +1 -0
- package/dist/common/guardrails.js +189 -0
- package/dist/common/guardrails.js.map +1 -0
- package/dist/common/index.d.ts +16 -0
- package/dist/common/index.d.ts.map +1 -0
- package/dist/common/index.js +32 -0
- package/dist/common/index.js.map +1 -0
- package/dist/common/log-sanitizer.d.ts +78 -0
- package/dist/common/log-sanitizer.d.ts.map +1 -0
- package/dist/common/log-sanitizer.js +340 -0
- package/dist/common/log-sanitizer.js.map +1 -0
- package/dist/common/policy-evaluator.d.ts +103 -0
- package/dist/common/policy-evaluator.d.ts.map +1 -0
- package/dist/common/policy-evaluator.js +200 -0
- package/dist/common/policy-evaluator.js.map +1 -0
- package/dist/common/resource.d.ts +62 -0
- package/dist/common/resource.d.ts.map +1 -0
- package/dist/common/resource.js +106 -0
- package/dist/common/resource.js.map +1 -0
- package/dist/common/tier-hints.d.ts +182 -0
- package/dist/common/tier-hints.d.ts.map +1 -0
- package/dist/common/tier-hints.js +209 -0
- package/dist/common/tier-hints.js.map +1 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +76 -0
- package/dist/index.js.map +1 -0
- package/dist/lint/forbidden-attributes.d.ts +149 -0
- package/dist/lint/forbidden-attributes.d.ts.map +1 -0
- package/dist/lint/forbidden-attributes.js +214 -0
- package/dist/lint/forbidden-attributes.js.map +1 -0
- package/dist/lint/index.d.ts +9 -0
- package/dist/lint/index.d.ts.map +1 -0
- package/dist/lint/index.js +16 -0
- package/dist/lint/index.js.map +1 -0
- package/dist/llmobs/index.d.ts +22 -0
- package/dist/llmobs/index.d.ts.map +1 -0
- package/dist/llmobs/index.js +29 -0
- package/dist/llmobs/index.js.map +1 -0
- package/dist/llmobs/tier1-exporter.d.ts +146 -0
- package/dist/llmobs/tier1-exporter.d.ts.map +1 -0
- package/dist/llmobs/tier1-exporter.js +196 -0
- package/dist/llmobs/tier1-exporter.js.map +1 -0
- package/dist/llmobs/tier2-summarizer.d.ts +268 -0
- package/dist/llmobs/tier2-summarizer.d.ts.map +1 -0
- package/dist/llmobs/tier2-summarizer.js +650 -0
- package/dist/llmobs/tier2-summarizer.js.map +1 -0
- package/dist/node/exporters/resilient-exporter.d.ts +77 -0
- package/dist/node/exporters/resilient-exporter.d.ts.map +1 -0
- package/dist/node/exporters/resilient-exporter.js +129 -0
- package/dist/node/exporters/resilient-exporter.js.map +1 -0
- package/dist/node/index.d.ts +11 -0
- package/dist/node/index.d.ts.map +1 -0
- package/dist/node/index.js +24 -0
- package/dist/node/index.js.map +1 -0
- package/dist/node/init.d.ts +75 -0
- package/dist/node/init.d.ts.map +1 -0
- package/dist/node/init.js +245 -0
- package/dist/node/init.js.map +1 -0
- package/dist/node/log-processor.d.ts +83 -0
- package/dist/node/log-processor.d.ts.map +1 -0
- package/dist/node/log-processor.js +266 -0
- package/dist/node/log-processor.js.map +1 -0
- package/dist/node/metrics-client.d.ts +66 -0
- package/dist/node/metrics-client.d.ts.map +1 -0
- package/dist/node/metrics-client.js +193 -0
- package/dist/node/metrics-client.js.map +1 -0
- package/dist/node/traced-socket.d.ts +76 -0
- package/dist/node/traced-socket.d.ts.map +1 -0
- package/dist/node/traced-socket.js +261 -0
- package/dist/node/traced-socket.js.map +1 -0
- package/dist/testing/in-memory-exporter.d.ts +179 -0
- package/dist/testing/in-memory-exporter.d.ts.map +1 -0
- package/dist/testing/in-memory-exporter.js +254 -0
- package/dist/testing/in-memory-exporter.js.map +1 -0
- package/dist/testing/index.d.ts +8 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +19 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/testing/test-init.d.ts +80 -0
- package/dist/testing/test-init.d.ts.map +1 -0
- package/dist/testing/test-init.js +144 -0
- package/dist/testing/test-init.js.map +1 -0
- package/dist/types/index.d.ts +40 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +23 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/policy.d.ts +92 -0
- package/dist/types/policy.d.ts.map +1 -0
- package/dist/types/policy.js +125 -0
- package/dist/types/policy.js.map +1 -0
- package/dist-esm/browser/index.d.ts +8 -0
- package/dist-esm/browser/index.d.ts.map +1 -0
- package/dist-esm/browser/index.js +9 -0
- package/dist-esm/browser/index.js.map +1 -0
- package/dist-esm/browser/init.d.ts +75 -0
- package/dist-esm/browser/init.d.ts.map +1 -0
- package/dist-esm/browser/init.js +162 -0
- package/dist-esm/browser/init.js.map +1 -0
- package/dist-esm/browser/resilient-exporter.d.ts +43 -0
- package/dist-esm/browser/resilient-exporter.d.ts.map +1 -0
- package/dist-esm/browser/resilient-exporter.js +84 -0
- package/dist-esm/browser/resilient-exporter.js.map +1 -0
- package/dist-esm/common/contracts/tier2-traces.d.ts +75 -0
- package/dist-esm/common/contracts/tier2-traces.d.ts.map +1 -0
- package/dist-esm/common/contracts/tier2-traces.js +178 -0
- package/dist-esm/common/contracts/tier2-traces.js.map +1 -0
- package/dist-esm/common/deployment-type.d.ts +18 -0
- package/dist-esm/common/deployment-type.d.ts.map +1 -0
- package/dist-esm/common/deployment-type.js +27 -0
- package/dist-esm/common/deployment-type.js.map +1 -0
- package/dist-esm/common/guardrails.d.ts +116 -0
- package/dist-esm/common/guardrails.d.ts.map +1 -0
- package/dist-esm/common/guardrails.js +179 -0
- package/dist-esm/common/guardrails.js.map +1 -0
- package/dist-esm/common/index.d.ts +16 -0
- package/dist-esm/common/index.d.ts.map +1 -0
- package/dist-esm/common/index.js +16 -0
- package/dist-esm/common/index.js.map +1 -0
- package/dist-esm/common/log-sanitizer.d.ts +78 -0
- package/dist-esm/common/log-sanitizer.d.ts.map +1 -0
- package/dist-esm/common/log-sanitizer.js +331 -0
- package/dist-esm/common/log-sanitizer.js.map +1 -0
- package/dist-esm/common/policy-evaluator.d.ts +103 -0
- package/dist-esm/common/policy-evaluator.d.ts.map +1 -0
- package/dist-esm/common/policy-evaluator.js +196 -0
- package/dist-esm/common/policy-evaluator.js.map +1 -0
- package/dist-esm/common/resource.d.ts +62 -0
- package/dist-esm/common/resource.d.ts.map +1 -0
- package/dist-esm/common/resource.js +100 -0
- package/dist-esm/common/resource.js.map +1 -0
- package/dist-esm/common/tier-hints.d.ts +182 -0
- package/dist-esm/common/tier-hints.d.ts.map +1 -0
- package/dist-esm/common/tier-hints.js +199 -0
- package/dist-esm/common/tier-hints.js.map +1 -0
- package/dist-esm/index.d.ts +43 -0
- package/dist-esm/index.d.ts.map +1 -0
- package/dist-esm/index.js +53 -0
- package/dist-esm/index.js.map +1 -0
- package/dist-esm/lint/forbidden-attributes.d.ts +149 -0
- package/dist-esm/lint/forbidden-attributes.d.ts.map +1 -0
- package/dist-esm/lint/forbidden-attributes.js +209 -0
- package/dist-esm/lint/forbidden-attributes.js.map +1 -0
- package/dist-esm/lint/index.d.ts +9 -0
- package/dist-esm/lint/index.d.ts.map +1 -0
- package/dist-esm/lint/index.js +9 -0
- package/dist-esm/lint/index.js.map +1 -0
- package/dist-esm/llmobs/index.d.ts +22 -0
- package/dist-esm/llmobs/index.d.ts.map +1 -0
- package/dist-esm/llmobs/index.js +22 -0
- package/dist-esm/llmobs/index.js.map +1 -0
- package/dist-esm/llmobs/tier1-exporter.d.ts +146 -0
- package/dist-esm/llmobs/tier1-exporter.d.ts.map +1 -0
- package/dist-esm/llmobs/tier1-exporter.js +190 -0
- package/dist-esm/llmobs/tier1-exporter.js.map +1 -0
- package/dist-esm/llmobs/tier2-summarizer.d.ts +268 -0
- package/dist-esm/llmobs/tier2-summarizer.d.ts.map +1 -0
- package/dist-esm/llmobs/tier2-summarizer.js +646 -0
- package/dist-esm/llmobs/tier2-summarizer.js.map +1 -0
- package/dist-esm/node/exporters/resilient-exporter.d.ts +77 -0
- package/dist-esm/node/exporters/resilient-exporter.d.ts.map +1 -0
- package/dist-esm/node/exporters/resilient-exporter.js +125 -0
- package/dist-esm/node/exporters/resilient-exporter.js.map +1 -0
- package/dist-esm/node/index.d.ts +11 -0
- package/dist-esm/node/index.d.ts.map +1 -0
- package/dist-esm/node/index.js +11 -0
- package/dist-esm/node/index.js.map +1 -0
- package/dist-esm/node/init.d.ts +75 -0
- package/dist-esm/node/init.d.ts.map +1 -0
- package/dist-esm/node/init.js +239 -0
- package/dist-esm/node/init.js.map +1 -0
- package/dist-esm/node/log-processor.d.ts +83 -0
- package/dist-esm/node/log-processor.d.ts.map +1 -0
- package/dist-esm/node/log-processor.js +261 -0
- package/dist-esm/node/log-processor.js.map +1 -0
- package/dist-esm/node/metrics-client.d.ts +66 -0
- package/dist-esm/node/metrics-client.d.ts.map +1 -0
- package/dist-esm/node/metrics-client.js +189 -0
- package/dist-esm/node/metrics-client.js.map +1 -0
- package/dist-esm/node/traced-socket.d.ts +76 -0
- package/dist-esm/node/traced-socket.d.ts.map +1 -0
- package/dist-esm/node/traced-socket.js +257 -0
- package/dist-esm/node/traced-socket.js.map +1 -0
- package/dist-esm/testing/in-memory-exporter.d.ts +179 -0
- package/dist-esm/testing/in-memory-exporter.d.ts.map +1 -0
- package/dist-esm/testing/in-memory-exporter.js +248 -0
- package/dist-esm/testing/in-memory-exporter.js.map +1 -0
- package/dist-esm/testing/index.d.ts +8 -0
- package/dist-esm/testing/index.d.ts.map +1 -0
- package/dist-esm/testing/index.js +8 -0
- package/dist-esm/testing/index.js.map +1 -0
- package/dist-esm/testing/test-init.d.ts +80 -0
- package/dist-esm/testing/test-init.d.ts.map +1 -0
- package/dist-esm/testing/test-init.js +137 -0
- package/dist-esm/testing/test-init.js.map +1 -0
- package/dist-esm/types/index.d.ts +40 -0
- package/dist-esm/types/index.d.ts.map +1 -0
- package/dist-esm/types/index.js +7 -0
- package/dist-esm/types/index.js.map +1 -0
- package/dist-esm/types/policy.d.ts +92 -0
- package/dist-esm/types/policy.d.ts.map +1 -0
- package/dist-esm/types/policy.js +122 -0
- package/dist-esm/types/policy.js.map +1 -0
- package/package.json +101 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
Superblocks Community Software License
|
|
2
|
+
|
|
3
|
+
This Superblocks Community License Agreement (the “Agreement”) sets forth the terms on which DayZero
|
|
4
|
+
Software, Inc. d/b/a Superblocks (“Superblocks”) makes available certain software made available by Superblocks
|
|
5
|
+
under this Agreement (the “Software”). BY INSTALLING, DOWNLOADING, ACCESSING, USING OR
|
|
6
|
+
DISTRIBUTING ANY OF THE SOFTWARE, YOU AGREE TO THE TERMS AND CONDITIONS OF THIS
|
|
7
|
+
AGREEMENT.IF YOU DO NOT AGREE TO SUCH TERMS AND CONDITIONS, YOU MUST NOT USE THE
|
|
8
|
+
SOFTWARE. IF YOU ARE RECEIVING THE SOFTWARE ON BEHALF OF A LEGAL ENTITY, YOU
|
|
9
|
+
REPRESENT AND WARRANT THAT YOU HAVE THE ACTUAL AUTHORITY TO AGREE TO THE
|
|
10
|
+
TERMS AND CONDITIONS OF THIS AGREEMENT ON BEHALF OF SUCH ENTITY. “Licensee” means you,
|
|
11
|
+
an individual, or the entity on whose behalf you are receiving the Software.
|
|
12
|
+
|
|
13
|
+
1. LICENSE GRANT AND CONDITIONS.
|
|
14
|
+
|
|
15
|
+
1.1 License. Subject to the terms and conditions of this Agreement, Superblocks hereby grants to Licensee a
|
|
16
|
+
non-exclusive, royalty-free, worldwide, non-transferable, non-sublicenseable license during the term of this
|
|
17
|
+
Agreement to: (a) use the Software; (b) prepare modifications and derivative works of the Software; (c)
|
|
18
|
+
distribute the Software (including without limitation in source code or object code form); and (d) reproduce
|
|
19
|
+
copies of the Software (the “License”). Licensee is not granted the right to, and Licensee shall not, exercise the
|
|
20
|
+
License for an Excluded Purpose. For purposes of this Agreement, “Excluded Purpose” means making
|
|
21
|
+
available any software-as-a-service, platform-as-a-service, infrastructure-as-a-service or other similar online
|
|
22
|
+
service that competes with Superblocks’ products or services.
|
|
23
|
+
|
|
24
|
+
1.2 Conditions. In consideration of the License, Licensee’s distribution of the Software is subject to the
|
|
25
|
+
following conditions:
|
|
26
|
+
|
|
27
|
+
a. Licensee must cause any Software modified by Licensee to carry prominent notices stating that Licensee
|
|
28
|
+
modified the Software.
|
|
29
|
+
b. On each Software copy, Licensee shall reproduce and not remove or alter all Superblocks or third party
|
|
30
|
+
copyright or other proprietary notices contained in the Software, and Licensee must provide the notice
|
|
31
|
+
below with each copy.
|
|
32
|
+
|
|
33
|
+
“This software is made available by DayZero Software, Inc. d/b/a Superblocks, under the terms of the
|
|
34
|
+
Superblocks Community License Agreement. © 2022 DayZero Software, Inc.”
|
|
35
|
+
|
|
36
|
+
1.3 Licensee Modifications. Licensee may add its own copyright notices to modifications made by Licensee
|
|
37
|
+
and may provide additional or different license terms and conditions for use, reproduction, or distribution of
|
|
38
|
+
Licensee’s modifications. While redistributing the Software or modifications thereof, Licensee may choose to
|
|
39
|
+
offer, for a fee or free of charge, support, warranty, indemnity, or other obligations. Licensee, and not
|
|
40
|
+
Superblocks, will be responsible for any such obligations.
|
|
41
|
+
|
|
42
|
+
1.4 No Sublicensing. The License does not include the right to sublicense the Software, however, each recipient
|
|
43
|
+
to which Licensee provides the Software may exercise the Licenses so long as such recipient agrees to the terms
|
|
44
|
+
and conditions of this Agreement.
|
|
45
|
+
|
|
46
|
+
2. TERM AND TERMINATION. This Agreement will continue unless and until earlier terminated as set forth
|
|
47
|
+
herein. If Licensee breaches any of its conditions or obligations under this Agreement, this Agreement will
|
|
48
|
+
terminate automatically and the License will terminate automatically and permanently.
|
|
49
|
+
|
|
50
|
+
3. INTELLECTUAL PROPERTY. As between the parties, Superblocks will retain all right, title, and interest in
|
|
51
|
+
the Software, and all intellectual property rights therein. Superblocks hereby reserves all rights not expressly
|
|
52
|
+
granted to Licensee in this Agreement. Superblocks hereby reserves all rights in its trademarks and service
|
|
53
|
+
marks, and no licenses therein are granted in this Agreement.
|
|
54
|
+
|
|
55
|
+
4. DISCLAIMER. SUPERBLOCKS HEREBY DISCLAIMS ANY AND ALL WARRANTIES AND
|
|
56
|
+
CONDITIONS, EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, AND SPECIFICALLY
|
|
57
|
+
DISCLAIMS ANY WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
|
|
58
|
+
PURPOSE, WITH RESPECT TO THE SOFTWARE.
|
|
59
|
+
|
|
60
|
+
5. LIMITATION OF LIABILITY. SUPERBLOCKS WILL NOT BE LIABLE FOR ANY DAMAGES OF
|
|
61
|
+
ANY KIND, INCLUDING BUT NOT LIMITED TO, LOST PROFITS OR ANY CONSEQUENTIAL,
|
|
62
|
+
SPECIAL, INCIDENTAL, INDIRECT, OR DIRECT DAMAGES, HOWEVER CAUSED AND ON ANY
|
|
63
|
+
THEORY OF LIABILITY, ARISING OUT OF THIS AGREEMENT. THE FOREGOING SHALL APPLY TO
|
|
64
|
+
THE EXTENT PERMITTED BY APPLICABLE LAW.
|
|
65
|
+
|
|
66
|
+
6. GENERAL.
|
|
67
|
+
|
|
68
|
+
6.1 Governing Law. This Agreement will be governed by and interpreted in accordance with the laws of the
|
|
69
|
+
state of California, without reference to its conflict of laws principles. If Licensee is located within the United
|
|
70
|
+
States, all disputes arising out of this Agreement are subject to the exclusive jurisdiction of courts located in San
|
|
71
|
+
Mateo County, California. USA. If Licensee is located outside of the United States, any dispute, controversy or
|
|
72
|
+
claim arising out of or relating to this Agreement will be referred to and finally determined by arbitration in
|
|
73
|
+
accordance with the JAMS International Arbitration Rules. The tribunal will consist of one neutral arbitrator.
|
|
74
|
+
The place of arbitration will be Palo Alto, California. The language to be used in the arbitral proceedings will be
|
|
75
|
+
English. Judgment upon the award rendered by the arbitrator may be entered in any court having jurisdiction
|
|
76
|
+
thereof.
|
|
77
|
+
|
|
78
|
+
6.2. Assignment. Licensee may not assign its rights under this Agreement to any third party. Superblocks may
|
|
79
|
+
freely assign its rights under this Agreement to any third party.
|
|
80
|
+
|
|
81
|
+
6.3. Other. This Agreement is the entire agreement between the parties regarding the subject matter hereof.
|
|
82
|
+
No amendment or modification of this Agreement will be valid or binding upon the parties unless made in
|
|
83
|
+
writing and signed by the duly authorized representatives of both parties. In the event that any provision,
|
|
84
|
+
including without limitation any condition, of this Agreement is held to be unenforceable, this Agreement and
|
|
85
|
+
all licenses and rights granted hereunder will immediately terminate. Waiver by Superblocks of a breach of any
|
|
86
|
+
provision of this Agreement or the failure by Superblocks to exercise any right hereunder will not be construed
|
|
87
|
+
as a waiver of any subsequent breach of that right or as a waiver of any other right.
|
package/README.md
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# @superblocksteam/telemetry
|
|
2
|
+
|
|
3
|
+
Canonical telemetry bootstrap package for all Superblocks services. This package provides policy-aware OpenTelemetry initialization with tier-based routing and sanitization.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This is the **ONLY approved way** to initialize OpenTelemetry in Superblocks services. Direct usage of `NodeSDK` or `WebTracerProvider` outside this package is prohibited.
|
|
8
|
+
|
|
9
|
+
## Tiered Telemetry Model
|
|
10
|
+
|
|
11
|
+
| Tier | Description | Egress |
|
|
12
|
+
|------|-------------|--------|
|
|
13
|
+
| **Tier 1** | Full fidelity debugging (code, prompts, stack traces) | Local only (cloud-prem) |
|
|
14
|
+
| **Tier 2** | Sanitized operational telemetry (latency, errors, token usage) | Exported by default |
|
|
15
|
+
| **Tier 3** | AI experience telemetry (prompts, responses, quality signals) | Exported by default |
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
### Node.js Services
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { initNodeTelemetry } from '@superblocksteam/telemetry/node';
|
|
23
|
+
import { getDefaultPolicy, DeploymentType } from '@superblocksteam/shared';
|
|
24
|
+
|
|
25
|
+
const policy = getDefaultPolicy(DeploymentType.CLOUD_PREM);
|
|
26
|
+
|
|
27
|
+
const telemetry = initNodeTelemetry({
|
|
28
|
+
serviceName: 'my-service',
|
|
29
|
+
serviceVersion: '1.0.0',
|
|
30
|
+
environment: process.env.NODE_ENV ?? 'development',
|
|
31
|
+
otlpUrl: process.env.OTEL_EXPORTER_OTLP_ENDPOINT,
|
|
32
|
+
}, policy);
|
|
33
|
+
|
|
34
|
+
// Graceful shutdown
|
|
35
|
+
process.on('SIGTERM', async () => {
|
|
36
|
+
await telemetry.shutdown();
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Browser
|
|
41
|
+
|
|
42
|
+
```typescript
|
|
43
|
+
import { initBrowserTelemetry } from '@superblocksteam/telemetry/browser';
|
|
44
|
+
import { getDefaultPolicy, DeploymentType } from '@superblocksteam/shared';
|
|
45
|
+
|
|
46
|
+
const policy = getDefaultPolicy(DeploymentType.CLOUD);
|
|
47
|
+
|
|
48
|
+
initBrowserTelemetry({
|
|
49
|
+
serviceName: 'superblocks-ui',
|
|
50
|
+
serviceVersion: '1.0.0',
|
|
51
|
+
environment: 'production',
|
|
52
|
+
otlpUrl: 'https://app.superblocks.com/api/v1/traces',
|
|
53
|
+
}, policy);
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Testing
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
import { initTestTelemetry } from '@superblocksteam/telemetry/testing';
|
|
60
|
+
|
|
61
|
+
describe('MyService', () => {
|
|
62
|
+
const { spanExporter, reset } = initTestTelemetry();
|
|
63
|
+
|
|
64
|
+
beforeEach(() => reset());
|
|
65
|
+
|
|
66
|
+
it('creates expected spans', async () => {
|
|
67
|
+
await myService.doSomething();
|
|
68
|
+
|
|
69
|
+
const spans = spanExporter.getSpans();
|
|
70
|
+
expect(spans).toHaveLength(1);
|
|
71
|
+
expect(spans[0].name).toBe('doSomething');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('does not leak Tier 1 data', async () => {
|
|
75
|
+
await myService.processWithSensitiveData();
|
|
76
|
+
|
|
77
|
+
spanExporter.assertNoAttribute('prompt', /.*/);
|
|
78
|
+
spanExporter.assertNoAttribute('code', /.*/);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Tier Policy Hints
|
|
84
|
+
|
|
85
|
+
Use tier policy hints to inform the Collector how to route specific spans. This is useful when the SDK knows something the Collector can't infer from attributes alone.
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
import { trace } from '@opentelemetry/api';
|
|
89
|
+
import { markSensitive, markForAIAnalysis, markDebugOnly } from '@superblocksteam/telemetry';
|
|
90
|
+
|
|
91
|
+
const tracer = trace.getTracer('my-service');
|
|
92
|
+
|
|
93
|
+
// Span containing secrets — Tier 1 only, never exported
|
|
94
|
+
tracer.startActiveSpan('decrypt_customer_secret', (span) => {
|
|
95
|
+
markSensitive(span);
|
|
96
|
+
// ... decrypt operation
|
|
97
|
+
span.end();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// GenAI span for quality analysis — include in Tier 3
|
|
101
|
+
tracer.startActiveSpan('gen_ai.chat', (span) => {
|
|
102
|
+
markForAIAnalysis(span);
|
|
103
|
+
span.setAttribute('gen_ai.system', 'anthropic');
|
|
104
|
+
// ... LLM call
|
|
105
|
+
span.end();
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// High-cardinality debug span — skip export (cost control)
|
|
109
|
+
tracer.startActiveSpan('debug.cache_lookup', (span) => {
|
|
110
|
+
markDebugOnly(span);
|
|
111
|
+
span.setAttribute('cache.key', cacheKey);
|
|
112
|
+
// ... lookup
|
|
113
|
+
span.end();
|
|
114
|
+
});
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Available Hints
|
|
118
|
+
|
|
119
|
+
| Helper | Hint Value | Effect |
|
|
120
|
+
|--------|------------|--------|
|
|
121
|
+
| `markSensitive(span)` | `tier1_only` | Tier 1 only, skip Tier 2/3 |
|
|
122
|
+
| `markForAIAnalysis(span)` | `include_tier3` | Include in Tier 3 (AI analytics) |
|
|
123
|
+
| `markDebugOnly(span)` | `skip_export` | Tier 1 only, skip all export |
|
|
124
|
+
|
|
125
|
+
You can also set hints directly:
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
import { TIER_HINT_ATTRIBUTE, TierPolicyHint } from '@superblocksteam/telemetry';
|
|
129
|
+
|
|
130
|
+
span.setAttribute(TIER_HINT_ATTRIBUTE, TierPolicyHint.TIER1_ONLY);
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Key Principles
|
|
134
|
+
|
|
135
|
+
1. **Policy Required** — Cannot initialize telemetry without a `TelemetryPolicy`
|
|
136
|
+
2. **Tier Enforcement** — Exporters are automatically enabled/disabled based on policy
|
|
137
|
+
3. **Sanitization at Source** — Tier 2/3 payloads are sanitized before export
|
|
138
|
+
4. **Fire-and-Forget** — Export failures never block core request paths
|
|
139
|
+
5. **Consistent Resources** — All services emit standardized resource attributes
|
|
140
|
+
|
|
141
|
+
## Package Structure
|
|
142
|
+
|
|
143
|
+
```
|
|
144
|
+
@superblocksteam/telemetry
|
|
145
|
+
├── /node # Node.js bootstrap (initNodeTelemetry)
|
|
146
|
+
├── /browser # Browser bootstrap (initBrowserTelemetry)
|
|
147
|
+
├── /testing # Test utilities (in-memory exporters)
|
|
148
|
+
└── /common # Shared utilities (resource, router, sanitizer)
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Related Documentation
|
|
152
|
+
|
|
153
|
+
- [O11y Refactor Project](../../engineering/projects/o11y-refactor/README.md)
|
|
154
|
+
- [Telemetry Policy Schema](../../engineering/projects/o11y-refactor/epics/epic-a1-telemetry-policy.md)
|
|
155
|
+
- [Tier 2 Traces Contract](https://github.com/superblocksteam/engineering/blob/main/projects/o11y-refactor/contracts/tier2-traces.v0.3.0.json)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser Telemetry Bootstrap
|
|
3
|
+
*
|
|
4
|
+
* This is the ONLY approved way to initialize telemetry in browser contexts.
|
|
5
|
+
*/
|
|
6
|
+
export { initBrowserTelemetry, getBrowserTelemetryInstance, isBrowserTelemetryInitialized, resetBrowserTelemetry, getEnvironmentFromHostname, type BrowserTelemetryInstance, } from './init.js';
|
|
7
|
+
export { getDefaultPolicy, DeploymentType } from '../types/policy.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,oBAAoB,EACpB,2BAA2B,EAC3B,6BAA6B,EAC7B,qBAAqB,EACrB,0BAA0B,EAC1B,KAAK,wBAAwB,GAC9B,MAAM,WAAW,CAAC;AAGnB,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Browser Telemetry Bootstrap
|
|
4
|
+
*
|
|
5
|
+
* This is the ONLY approved way to initialize telemetry in browser contexts.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.DeploymentType = exports.getDefaultPolicy = exports.getEnvironmentFromHostname = exports.resetBrowserTelemetry = exports.isBrowserTelemetryInitialized = exports.getBrowserTelemetryInstance = exports.initBrowserTelemetry = void 0;
|
|
9
|
+
var init_js_1 = require("./init.js");
|
|
10
|
+
Object.defineProperty(exports, "initBrowserTelemetry", { enumerable: true, get: function () { return init_js_1.initBrowserTelemetry; } });
|
|
11
|
+
Object.defineProperty(exports, "getBrowserTelemetryInstance", { enumerable: true, get: function () { return init_js_1.getBrowserTelemetryInstance; } });
|
|
12
|
+
Object.defineProperty(exports, "isBrowserTelemetryInitialized", { enumerable: true, get: function () { return init_js_1.isBrowserTelemetryInitialized; } });
|
|
13
|
+
Object.defineProperty(exports, "resetBrowserTelemetry", { enumerable: true, get: function () { return init_js_1.resetBrowserTelemetry; } });
|
|
14
|
+
Object.defineProperty(exports, "getEnvironmentFromHostname", { enumerable: true, get: function () { return init_js_1.getEnvironmentFromHostname; } });
|
|
15
|
+
// Re-export policy utilities for convenience
|
|
16
|
+
var policy_js_1 = require("../types/policy.js");
|
|
17
|
+
Object.defineProperty(exports, "getDefaultPolicy", { enumerable: true, get: function () { return policy_js_1.getDefaultPolicy; } });
|
|
18
|
+
Object.defineProperty(exports, "DeploymentType", { enumerable: true, get: function () { return policy_js_1.DeploymentType; } });
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/browser/index.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAEH,qCAOmB;AANjB,+GAAA,oBAAoB,OAAA;AACpB,sHAAA,2BAA2B,OAAA;AAC3B,wHAAA,6BAA6B,OAAA;AAC7B,gHAAA,qBAAqB,OAAA;AACrB,qHAAA,0BAA0B,OAAA;AAI5B,6CAA6C;AAC7C,gDAAsE;AAA7D,6GAAA,gBAAgB,OAAA;AAAE,2GAAA,cAAc,OAAA"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser Telemetry Bootstrap
|
|
3
|
+
*
|
|
4
|
+
* This is the ONLY approved way to initialize telemetry in browser contexts.
|
|
5
|
+
* Direct WebTracerProvider usage outside this package is prohibited.
|
|
6
|
+
*/
|
|
7
|
+
import { Tracer } from "@opentelemetry/api";
|
|
8
|
+
import { WebTracerProvider } from "@opentelemetry/sdk-trace-web";
|
|
9
|
+
import { TelemetryPolicyEvaluator } from "../common/policy-evaluator.js";
|
|
10
|
+
import type { BrowserTelemetryConfig } from "../types/index.js";
|
|
11
|
+
import { TelemetryPolicy } from "../types/policy.js";
|
|
12
|
+
/**
|
|
13
|
+
* Browser telemetry instance.
|
|
14
|
+
*/
|
|
15
|
+
export interface BrowserTelemetryInstance {
|
|
16
|
+
/** The underlying WebTracerProvider */
|
|
17
|
+
provider: WebTracerProvider;
|
|
18
|
+
/** Policy evaluator for runtime decisions */
|
|
19
|
+
policyEvaluator: TelemetryPolicyEvaluator;
|
|
20
|
+
/** Get a tracer */
|
|
21
|
+
getTracer: (name?: string) => Tracer;
|
|
22
|
+
/** Graceful shutdown */
|
|
23
|
+
shutdown: () => Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Initialize browser telemetry with policy enforcement.
|
|
27
|
+
*
|
|
28
|
+
* Browser telemetry is always sanitized (Tier 2) since it runs in untrusted context.
|
|
29
|
+
* Full fidelity Tier 1 data should never be emitted from the browser.
|
|
30
|
+
*
|
|
31
|
+
* @param config - Browser configuration
|
|
32
|
+
* @param policy - Telemetry policy (REQUIRED)
|
|
33
|
+
* @returns Browser telemetry instance
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* import { initBrowserTelemetry } from '@superblocksteam/telemetry/browser';
|
|
38
|
+
* import { getDefaultPolicy, DeploymentType } from '@superblocksteam/shared';
|
|
39
|
+
*
|
|
40
|
+
* const policy = getDefaultPolicy(DeploymentType.CLOUD);
|
|
41
|
+
* const telemetry = initBrowserTelemetry({
|
|
42
|
+
* serviceName: 'superblocks-ui',
|
|
43
|
+
* serviceVersion: '1.0.0',
|
|
44
|
+
* environment: 'production',
|
|
45
|
+
* otlpUrl: 'https://app.superblocks.com/api/v1/traces',
|
|
46
|
+
* }, policy);
|
|
47
|
+
*
|
|
48
|
+
* const tracer = telemetry.getTracer();
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare function initBrowserTelemetry(config: BrowserTelemetryConfig, policy: TelemetryPolicy): BrowserTelemetryInstance;
|
|
52
|
+
/**
|
|
53
|
+
* Get the current browser telemetry instance.
|
|
54
|
+
*
|
|
55
|
+
* @throws Error if not initialized
|
|
56
|
+
*/
|
|
57
|
+
export declare function getBrowserTelemetryInstance(): BrowserTelemetryInstance;
|
|
58
|
+
/**
|
|
59
|
+
* Check if browser telemetry is initialized.
|
|
60
|
+
*/
|
|
61
|
+
export declare function isBrowserTelemetryInitialized(): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Reset browser telemetry (for testing only).
|
|
64
|
+
* @internal
|
|
65
|
+
*/
|
|
66
|
+
export declare function resetBrowserTelemetry(): void;
|
|
67
|
+
/**
|
|
68
|
+
* Derive environment from hostname.
|
|
69
|
+
* Utility for browser context where env vars aren't available.
|
|
70
|
+
*
|
|
71
|
+
* @param hostname - The hostname to analyze
|
|
72
|
+
* @returns Environment string
|
|
73
|
+
*/
|
|
74
|
+
export declare function getEnvironmentFromHostname(hostname: string): string;
|
|
75
|
+
//# sourceMappingURL=init.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/browser/init.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAS,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAUjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,EAAE,eAAe,EAAiB,MAAM,oBAAoB,CAAC;AAGpE;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,uCAAuC;IACvC,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,6CAA6C;IAC7C,eAAe,EAAE,wBAAwB,CAAC;IAC1C,mBAAmB;IACnB,SAAS,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;IACrC,wBAAwB;IACxB,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC/B;AAmCD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,sBAAsB,EAC9B,MAAM,EAAE,eAAe,GACtB,wBAAwB,CAkE1B;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,IAAI,wBAAwB,CAOtE;AAED;;GAEG;AACH,wBAAgB,6BAA6B,IAAI,OAAO,CAEvD;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,IAAI,IAAI,CAE5C;AAED;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAWnE"}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Browser Telemetry Bootstrap
|
|
4
|
+
*
|
|
5
|
+
* This is the ONLY approved way to initialize telemetry in browser contexts.
|
|
6
|
+
* Direct WebTracerProvider usage outside this package is prohibited.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.initBrowserTelemetry = initBrowserTelemetry;
|
|
10
|
+
exports.getBrowserTelemetryInstance = getBrowserTelemetryInstance;
|
|
11
|
+
exports.isBrowserTelemetryInitialized = isBrowserTelemetryInitialized;
|
|
12
|
+
exports.resetBrowserTelemetry = resetBrowserTelemetry;
|
|
13
|
+
exports.getEnvironmentFromHostname = getEnvironmentFromHostname;
|
|
14
|
+
const api_1 = require("@opentelemetry/api");
|
|
15
|
+
const sdk_trace_web_1 = require("@opentelemetry/sdk-trace-web");
|
|
16
|
+
const sdk_trace_base_1 = require("@opentelemetry/sdk-trace-base");
|
|
17
|
+
const exporter_trace_otlp_http_1 = require("@opentelemetry/exporter-trace-otlp-http");
|
|
18
|
+
const core_1 = require("@opentelemetry/core");
|
|
19
|
+
const resource_js_1 = require("../common/resource.js");
|
|
20
|
+
const policy_evaluator_js_1 = require("../common/policy-evaluator.js");
|
|
21
|
+
const policy_js_1 = require("../types/policy.js");
|
|
22
|
+
const resilient_exporter_js_1 = require("./resilient-exporter.js");
|
|
23
|
+
// Singleton instance
|
|
24
|
+
let instance;
|
|
25
|
+
/**
|
|
26
|
+
* Validate browser telemetry configuration.
|
|
27
|
+
*
|
|
28
|
+
* @param config - Configuration to validate
|
|
29
|
+
* @throws Error if configuration is invalid
|
|
30
|
+
*/
|
|
31
|
+
function validateBrowserTelemetryConfig(config) {
|
|
32
|
+
if (!config.serviceName?.trim()) {
|
|
33
|
+
throw new Error("[Telemetry] serviceName is required and cannot be empty");
|
|
34
|
+
}
|
|
35
|
+
if (!config.serviceVersion?.trim()) {
|
|
36
|
+
throw new Error("[Telemetry] serviceVersion is required and cannot be empty");
|
|
37
|
+
}
|
|
38
|
+
if (!config.environment?.trim()) {
|
|
39
|
+
throw new Error("[Telemetry] environment is required and cannot be empty");
|
|
40
|
+
}
|
|
41
|
+
if (!config.otlpUrl?.trim()) {
|
|
42
|
+
throw new Error("[Telemetry] otlpUrl is required for browser telemetry");
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
new URL(config.otlpUrl);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
throw new Error(`[Telemetry] Invalid otlpUrl: ${config.otlpUrl} (${error.message})`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Initialize browser telemetry with policy enforcement.
|
|
53
|
+
*
|
|
54
|
+
* Browser telemetry is always sanitized (Tier 2) since it runs in untrusted context.
|
|
55
|
+
* Full fidelity Tier 1 data should never be emitted from the browser.
|
|
56
|
+
*
|
|
57
|
+
* @param config - Browser configuration
|
|
58
|
+
* @param policy - Telemetry policy (REQUIRED)
|
|
59
|
+
* @returns Browser telemetry instance
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* import { initBrowserTelemetry } from '@superblocksteam/telemetry/browser';
|
|
64
|
+
* import { getDefaultPolicy, DeploymentType } from '@superblocksteam/shared';
|
|
65
|
+
*
|
|
66
|
+
* const policy = getDefaultPolicy(DeploymentType.CLOUD);
|
|
67
|
+
* const telemetry = initBrowserTelemetry({
|
|
68
|
+
* serviceName: 'superblocks-ui',
|
|
69
|
+
* serviceVersion: '1.0.0',
|
|
70
|
+
* environment: 'production',
|
|
71
|
+
* otlpUrl: 'https://app.superblocks.com/api/v1/traces',
|
|
72
|
+
* }, policy);
|
|
73
|
+
*
|
|
74
|
+
* const tracer = telemetry.getTracer();
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
function initBrowserTelemetry(config, policy) {
|
|
78
|
+
// Policy is required
|
|
79
|
+
if (!policy) {
|
|
80
|
+
throw new Error("[Telemetry] Policy is required. Cannot initialize telemetry without a policy.");
|
|
81
|
+
}
|
|
82
|
+
// Validate config
|
|
83
|
+
validateBrowserTelemetryConfig(config);
|
|
84
|
+
// Return existing instance if already initialized
|
|
85
|
+
if (instance) {
|
|
86
|
+
console.warn("[Telemetry] Browser provider already initialized");
|
|
87
|
+
return instance;
|
|
88
|
+
}
|
|
89
|
+
const policyEvaluator = new policy_evaluator_js_1.TelemetryPolicyEvaluator(policy);
|
|
90
|
+
const resource = (0, resource_js_1.buildResource)(config);
|
|
91
|
+
// Build span processors based on policy
|
|
92
|
+
// Use isExportEnabled (not canExport) - sampling applies at runtime, not initialization
|
|
93
|
+
const spanProcessors = policyEvaluator.isExportEnabled(policy_js_1.TelemetryTier.TIER_2_OPERATIONAL)
|
|
94
|
+
? [
|
|
95
|
+
new sdk_trace_base_1.BatchSpanProcessor(new resilient_exporter_js_1.BrowserResilientExporter({
|
|
96
|
+
delegate: new exporter_trace_otlp_http_1.OTLPTraceExporter({ url: config.otlpUrl }),
|
|
97
|
+
})),
|
|
98
|
+
]
|
|
99
|
+
: [];
|
|
100
|
+
// Create provider with span processors in constructor (OTEL v2.x API)
|
|
101
|
+
const provider = new sdk_trace_web_1.WebTracerProvider({
|
|
102
|
+
resource,
|
|
103
|
+
spanProcessors,
|
|
104
|
+
});
|
|
105
|
+
// Register with composite propagator for W3C TraceContext and Baggage
|
|
106
|
+
provider.register({
|
|
107
|
+
propagator: new core_1.CompositePropagator({
|
|
108
|
+
propagators: [
|
|
109
|
+
new core_1.W3CBaggagePropagator(),
|
|
110
|
+
new core_1.W3CTraceContextPropagator(),
|
|
111
|
+
],
|
|
112
|
+
}),
|
|
113
|
+
});
|
|
114
|
+
console.debug(`[Telemetry] Browser tracing initialized for ${config.serviceName} (${policy.deploymentType})`);
|
|
115
|
+
instance = {
|
|
116
|
+
provider,
|
|
117
|
+
policyEvaluator,
|
|
118
|
+
getTracer: (name) => api_1.trace.getTracer(name ?? config.serviceName, config.serviceVersion),
|
|
119
|
+
shutdown: async () => {
|
|
120
|
+
await provider.shutdown();
|
|
121
|
+
instance = undefined;
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
return instance;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Get the current browser telemetry instance.
|
|
128
|
+
*
|
|
129
|
+
* @throws Error if not initialized
|
|
130
|
+
*/
|
|
131
|
+
function getBrowserTelemetryInstance() {
|
|
132
|
+
if (!instance) {
|
|
133
|
+
throw new Error("[Telemetry] Not initialized. Call initBrowserTelemetry() first.");
|
|
134
|
+
}
|
|
135
|
+
return instance;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Check if browser telemetry is initialized.
|
|
139
|
+
*/
|
|
140
|
+
function isBrowserTelemetryInitialized() {
|
|
141
|
+
return instance !== undefined;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Reset browser telemetry (for testing only).
|
|
145
|
+
* @internal
|
|
146
|
+
*/
|
|
147
|
+
function resetBrowserTelemetry() {
|
|
148
|
+
instance = undefined;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Derive environment from hostname.
|
|
152
|
+
* Utility for browser context where env vars aren't available.
|
|
153
|
+
*
|
|
154
|
+
* @param hostname - The hostname to analyze
|
|
155
|
+
* @returns Environment string
|
|
156
|
+
*/
|
|
157
|
+
function getEnvironmentFromHostname(hostname) {
|
|
158
|
+
if (hostname.includes("localhost") || hostname.includes("127.0.0.1")) {
|
|
159
|
+
return "local";
|
|
160
|
+
}
|
|
161
|
+
if (hostname.includes("staging") || hostname.includes("stg")) {
|
|
162
|
+
return "staging";
|
|
163
|
+
}
|
|
164
|
+
if (hostname.includes("dev") || hostname.includes("development")) {
|
|
165
|
+
return "development";
|
|
166
|
+
}
|
|
167
|
+
return "production";
|
|
168
|
+
}
|
|
169
|
+
//# sourceMappingURL=init.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.js","sourceRoot":"","sources":["../../src/browser/init.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser Resilient Exporter
|
|
3
|
+
*
|
|
4
|
+
* Simplified resilient exporter for browser environments.
|
|
5
|
+
* Ensures export failures don't affect the main thread.
|
|
6
|
+
*/
|
|
7
|
+
import type { SpanExporter, ReadableSpan } from "@opentelemetry/sdk-trace-base";
|
|
8
|
+
import { ExportResult } from "@opentelemetry/core";
|
|
9
|
+
/**
|
|
10
|
+
* Configuration for the browser resilient exporter.
|
|
11
|
+
*/
|
|
12
|
+
export interface BrowserResilientExporterConfig {
|
|
13
|
+
/** Underlying exporter to wrap */
|
|
14
|
+
delegate: SpanExporter;
|
|
15
|
+
/** Max items to buffer before dropping (default: 512, lower than Node for memory) */
|
|
16
|
+
maxQueueSize?: number;
|
|
17
|
+
/** Export timeout in ms (default: 10000, shorter for browser) */
|
|
18
|
+
exportTimeoutMs?: number;
|
|
19
|
+
/** Callback when items are dropped */
|
|
20
|
+
onDrop?: (count: number, reason: "queue_full" | "export_failed" | "timeout") => void;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Browser-compatible resilient exporter.
|
|
24
|
+
*
|
|
25
|
+
* CRITICAL: Export failures must never block or affect the main thread.
|
|
26
|
+
* This wrapper catches all errors and timeouts.
|
|
27
|
+
*/
|
|
28
|
+
export declare class BrowserResilientExporter implements SpanExporter {
|
|
29
|
+
private readonly delegate;
|
|
30
|
+
private readonly maxQueueSize;
|
|
31
|
+
private readonly exportTimeoutMs;
|
|
32
|
+
private readonly onDrop;
|
|
33
|
+
private queuedCount;
|
|
34
|
+
private shuttingDown;
|
|
35
|
+
constructor(config: BrowserResilientExporterConfig);
|
|
36
|
+
/**
|
|
37
|
+
* Export spans with resilient error handling.
|
|
38
|
+
*/
|
|
39
|
+
export(spans: ReadableSpan[], resultCallback: (result: ExportResult) => void): void;
|
|
40
|
+
shutdown(): Promise<void>;
|
|
41
|
+
forceFlush(): Promise<void>;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=resilient-exporter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resilient-exporter.d.ts","sourceRoot":"","sources":["../../src/browser/resilient-exporter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAChF,OAAO,EAAE,YAAY,EAAoB,MAAM,qBAAqB,CAAC;AAErE;;GAEG;AACH,MAAM,WAAW,8BAA8B;IAC7C,kCAAkC;IAClC,QAAQ,EAAE,YAAY,CAAC;IACvB,qFAAqF;IACrF,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iEAAiE;IACjE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,sCAAsC;IACtC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,eAAe,GAAG,SAAS,KAAK,IAAI,CAAC;CACtF;AAED;;;;;GAKG;AACH,qBAAa,wBAAyB,YAAW,YAAY;IAC3D,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAe;IACxC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IACzC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAGb;IAEV,OAAO,CAAC,WAAW,CAAK;IACxB,OAAO,CAAC,YAAY,CAAS;gBAEjB,MAAM,EAAE,8BAA8B;IAOlD;;OAEG;IACH,MAAM,CACJ,KAAK,EAAE,YAAY,EAAE,EACrB,cAAc,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,IAAI,GAC7C,IAAI;IAiDD,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAKzB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;CAGlC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Browser Resilient Exporter
|
|
4
|
+
*
|
|
5
|
+
* Simplified resilient exporter for browser environments.
|
|
6
|
+
* Ensures export failures don't affect the main thread.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.BrowserResilientExporter = void 0;
|
|
10
|
+
const core_1 = require("@opentelemetry/core");
|
|
11
|
+
/**
|
|
12
|
+
* Browser-compatible resilient exporter.
|
|
13
|
+
*
|
|
14
|
+
* CRITICAL: Export failures must never block or affect the main thread.
|
|
15
|
+
* This wrapper catches all errors and timeouts.
|
|
16
|
+
*/
|
|
17
|
+
class BrowserResilientExporter {
|
|
18
|
+
delegate;
|
|
19
|
+
maxQueueSize;
|
|
20
|
+
exportTimeoutMs;
|
|
21
|
+
onDrop;
|
|
22
|
+
queuedCount = 0;
|
|
23
|
+
shuttingDown = false;
|
|
24
|
+
constructor(config) {
|
|
25
|
+
this.delegate = config.delegate;
|
|
26
|
+
this.maxQueueSize = config.maxQueueSize ?? 512;
|
|
27
|
+
this.exportTimeoutMs = config.exportTimeoutMs ?? 10000;
|
|
28
|
+
this.onDrop = config.onDrop ?? (() => { });
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Export spans with resilient error handling.
|
|
32
|
+
*/
|
|
33
|
+
export(spans, resultCallback) {
|
|
34
|
+
// Reject during shutdown
|
|
35
|
+
if (this.shuttingDown) {
|
|
36
|
+
resultCallback({ code: core_1.ExportResultCode.SUCCESS });
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
// Check backpressure
|
|
40
|
+
if (this.queuedCount + spans.length > this.maxQueueSize) {
|
|
41
|
+
this.onDrop(spans.length, "queue_full");
|
|
42
|
+
resultCallback({ code: core_1.ExportResultCode.SUCCESS });
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
this.queuedCount += spans.length;
|
|
46
|
+
let completed = false;
|
|
47
|
+
// Timeout handler
|
|
48
|
+
const timeoutId = setTimeout(() => {
|
|
49
|
+
if (completed)
|
|
50
|
+
return;
|
|
51
|
+
completed = true;
|
|
52
|
+
this.queuedCount -= spans.length;
|
|
53
|
+
this.onDrop(spans.length, "timeout");
|
|
54
|
+
resultCallback({ code: core_1.ExportResultCode.SUCCESS });
|
|
55
|
+
}, this.exportTimeoutMs);
|
|
56
|
+
try {
|
|
57
|
+
this.delegate.export(spans, (result) => {
|
|
58
|
+
if (completed)
|
|
59
|
+
return;
|
|
60
|
+
completed = true;
|
|
61
|
+
clearTimeout(timeoutId);
|
|
62
|
+
this.queuedCount -= spans.length;
|
|
63
|
+
if (result.code !== core_1.ExportResultCode.SUCCESS) {
|
|
64
|
+
this.onDrop(spans.length, "export_failed");
|
|
65
|
+
}
|
|
66
|
+
resultCallback({ code: core_1.ExportResultCode.SUCCESS });
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
if (completed)
|
|
71
|
+
return;
|
|
72
|
+
completed = true;
|
|
73
|
+
clearTimeout(timeoutId);
|
|
74
|
+
this.queuedCount -= spans.length;
|
|
75
|
+
this.onDrop(spans.length, "export_failed");
|
|
76
|
+
resultCallback({ code: core_1.ExportResultCode.SUCCESS });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async shutdown() {
|
|
80
|
+
this.shuttingDown = true;
|
|
81
|
+
return this.delegate.shutdown();
|
|
82
|
+
}
|
|
83
|
+
async forceFlush() {
|
|
84
|
+
return this.delegate.forceFlush?.() ?? Promise.resolve();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.BrowserResilientExporter = BrowserResilientExporter;
|
|
88
|
+
//# sourceMappingURL=resilient-exporter.js.map
|