react-native-otel 0.1.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 (105) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +37 -0
  3. package/lib/module/context/span-context.js +14 -0
  4. package/lib/module/context/span-context.js.map +1 -0
  5. package/lib/module/core/attributes.js +43 -0
  6. package/lib/module/core/attributes.js.map +1 -0
  7. package/lib/module/core/clock.js +8 -0
  8. package/lib/module/core/clock.js.map +1 -0
  9. package/lib/module/core/ids.js +16 -0
  10. package/lib/module/core/ids.js.map +1 -0
  11. package/lib/module/core/log-record.js +41 -0
  12. package/lib/module/core/log-record.js.map +1 -0
  13. package/lib/module/core/meter.js +70 -0
  14. package/lib/module/core/meter.js.map +1 -0
  15. package/lib/module/core/resource.js +20 -0
  16. package/lib/module/core/resource.js.map +1 -0
  17. package/lib/module/core/span.js +96 -0
  18. package/lib/module/core/span.js.map +1 -0
  19. package/lib/module/core/tracer.js +48 -0
  20. package/lib/module/core/tracer.js.map +1 -0
  21. package/lib/module/exporters/console-exporter.js +53 -0
  22. package/lib/module/exporters/console-exporter.js.map +1 -0
  23. package/lib/module/exporters/otlp-http-exporter.js +317 -0
  24. package/lib/module/exporters/otlp-http-exporter.js.map +1 -0
  25. package/lib/module/exporters/types.js +4 -0
  26. package/lib/module/exporters/types.js.map +1 -0
  27. package/lib/module/index.js +24 -0
  28. package/lib/module/index.js.map +1 -0
  29. package/lib/module/instrumentation/errors.js +63 -0
  30. package/lib/module/instrumentation/errors.js.map +1 -0
  31. package/lib/module/instrumentation/lifecycle.js +15 -0
  32. package/lib/module/instrumentation/lifecycle.js.map +1 -0
  33. package/lib/module/instrumentation/navigation.js +51 -0
  34. package/lib/module/instrumentation/navigation.js.map +1 -0
  35. package/lib/module/instrumentation/network.js +183 -0
  36. package/lib/module/instrumentation/network.js.map +1 -0
  37. package/lib/module/package.json +1 -0
  38. package/lib/module/react/OtelProvider.js +57 -0
  39. package/lib/module/react/OtelProvider.js.map +1 -0
  40. package/lib/module/react/useOtel.js +12 -0
  41. package/lib/module/react/useOtel.js.map +1 -0
  42. package/lib/module/sdk.js +127 -0
  43. package/lib/module/sdk.js.map +1 -0
  44. package/lib/typescript/package.json +1 -0
  45. package/lib/typescript/src/context/span-context.d.ts +9 -0
  46. package/lib/typescript/src/context/span-context.d.ts.map +1 -0
  47. package/lib/typescript/src/core/attributes.d.ts +6 -0
  48. package/lib/typescript/src/core/attributes.d.ts.map +1 -0
  49. package/lib/typescript/src/core/clock.d.ts +2 -0
  50. package/lib/typescript/src/core/clock.d.ts.map +1 -0
  51. package/lib/typescript/src/core/ids.d.ts +3 -0
  52. package/lib/typescript/src/core/ids.d.ts.map +1 -0
  53. package/lib/typescript/src/core/log-record.d.ts +15 -0
  54. package/lib/typescript/src/core/log-record.d.ts.map +1 -0
  55. package/lib/typescript/src/core/meter.d.ts +30 -0
  56. package/lib/typescript/src/core/meter.d.ts.map +1 -0
  57. package/lib/typescript/src/core/resource.d.ts +25 -0
  58. package/lib/typescript/src/core/resource.d.ts.map +1 -0
  59. package/lib/typescript/src/core/span.d.ts +77 -0
  60. package/lib/typescript/src/core/span.d.ts.map +1 -0
  61. package/lib/typescript/src/core/tracer.d.ts +21 -0
  62. package/lib/typescript/src/core/tracer.d.ts.map +1 -0
  63. package/lib/typescript/src/exporters/console-exporter.d.ts +17 -0
  64. package/lib/typescript/src/exporters/console-exporter.d.ts.map +1 -0
  65. package/lib/typescript/src/exporters/otlp-http-exporter.d.ts +58 -0
  66. package/lib/typescript/src/exporters/otlp-http-exporter.d.ts.map +1 -0
  67. package/lib/typescript/src/exporters/types.d.ts +25 -0
  68. package/lib/typescript/src/exporters/types.d.ts.map +1 -0
  69. package/lib/typescript/src/index.d.ts +25 -0
  70. package/lib/typescript/src/index.d.ts.map +1 -0
  71. package/lib/typescript/src/instrumentation/errors.d.ts +15 -0
  72. package/lib/typescript/src/instrumentation/errors.d.ts.map +1 -0
  73. package/lib/typescript/src/instrumentation/lifecycle.d.ts +3 -0
  74. package/lib/typescript/src/instrumentation/lifecycle.d.ts.map +1 -0
  75. package/lib/typescript/src/instrumentation/navigation.d.ts +7 -0
  76. package/lib/typescript/src/instrumentation/navigation.d.ts.map +1 -0
  77. package/lib/typescript/src/instrumentation/network.d.ts +33 -0
  78. package/lib/typescript/src/instrumentation/network.d.ts.map +1 -0
  79. package/lib/typescript/src/react/OtelProvider.d.ts +21 -0
  80. package/lib/typescript/src/react/OtelProvider.d.ts.map +1 -0
  81. package/lib/typescript/src/react/useOtel.d.ts +3 -0
  82. package/lib/typescript/src/react/useOtel.d.ts.map +1 -0
  83. package/lib/typescript/src/sdk.d.ts +50 -0
  84. package/lib/typescript/src/sdk.d.ts.map +1 -0
  85. package/package.json +125 -0
  86. package/src/context/span-context.ts +17 -0
  87. package/src/core/attributes.ts +61 -0
  88. package/src/core/clock.ts +5 -0
  89. package/src/core/ids.ts +15 -0
  90. package/src/core/log-record.ts +58 -0
  91. package/src/core/meter.ts +82 -0
  92. package/src/core/resource.ts +50 -0
  93. package/src/core/span.ts +161 -0
  94. package/src/core/tracer.ts +75 -0
  95. package/src/exporters/console-exporter.ts +89 -0
  96. package/src/exporters/otlp-http-exporter.ts +377 -0
  97. package/src/exporters/types.ts +29 -0
  98. package/src/index.ts +63 -0
  99. package/src/instrumentation/errors.ts +95 -0
  100. package/src/instrumentation/lifecycle.ts +17 -0
  101. package/src/instrumentation/navigation.ts +61 -0
  102. package/src/instrumentation/network.ts +253 -0
  103. package/src/react/OtelProvider.tsx +98 -0
  104. package/src/react/useOtel.ts +14 -0
  105. package/src/sdk.ts +179 -0
@@ -0,0 +1,183 @@
1
+ "use strict";
2
+
3
+ import { ATTR_HTTP_REQUEST_METHOD, ATTR_HTTP_RESPONSE_STATUS_CODE } from '@opentelemetry/semantic-conventions';
4
+ import { spanContext } from "../context/span-context.js";
5
+ import { generateSpanId } from "../core/ids.js";
6
+ // Concurrent-safe: parent context is captured by value at request start
7
+ const activeNetworkSpans = new Map();
8
+
9
+ // ─── Axios shape (subset we care about) ─────────────────────────────────────
10
+
11
+ // ─── Redaction helpers ───────────────────────────────────────────────────────
12
+
13
+ // Builds the set of leaf keys to redact for a given section prefix.
14
+ // e.g. section='header', paths=['header.authorization','body.password']
15
+ // → Set { 'authorization' }
16
+ function leafKeysForSection(section, paths) {
17
+ const prefix = `${section}.`;
18
+ const result = new Set();
19
+ for (const path of paths) {
20
+ if (path.toLowerCase().startsWith(prefix)) {
21
+ result.add(path.slice(prefix.length).toLowerCase());
22
+ }
23
+ }
24
+ return result;
25
+ }
26
+
27
+ // Shallow-redacts an object, replacing blacklisted keys with '[REDACTED]'.
28
+ // Case-insensitive on keys. Returns the original object reference when
29
+ // there are no sensitive keys to save an allocation.
30
+ function redactObject(obj, sensitive) {
31
+ if (sensitive.size === 0) return obj;
32
+ const result = {};
33
+ for (const key of Object.keys(obj)) {
34
+ result[key] = sensitive.has(key.toLowerCase()) ? '[REDACTED]' : obj[key];
35
+ }
36
+ return result;
37
+ }
38
+
39
+ // Tries to produce a plain object from a request/response body.
40
+ // Handles object and JSON-string forms; skips Blobs, FormData, etc.
41
+ function normalizeBody(data) {
42
+ if (data === null || data === undefined) return undefined;
43
+ if (typeof data === 'object' && !Array.isArray(data)) {
44
+ return data;
45
+ }
46
+ if (typeof data === 'string') {
47
+ try {
48
+ const parsed = JSON.parse(data);
49
+ if (parsed !== null && typeof parsed === 'object' && !Array.isArray(parsed)) {
50
+ return parsed;
51
+ }
52
+ } catch {
53
+ // not JSON — skip
54
+ }
55
+ }
56
+ return undefined;
57
+ }
58
+
59
+ // Serializes an object to a JSON string for use as a span attribute.
60
+ // Returns undefined when serialization fails (circular refs, etc.).
61
+ function toJsonAttr(obj) {
62
+ try {
63
+ return JSON.stringify(obj);
64
+ } catch {
65
+ return undefined;
66
+ }
67
+ }
68
+
69
+ // ─── Factory ─────────────────────────────────────────────────────────────────
70
+
71
+ export function createAxiosInstrumentation(tracer, options) {
72
+ const paths = (options?.sensitiveKeys ?? []).map(k => k.toLowerCase());
73
+
74
+ // Pre-compute sensitive leaf-key sets once at setup time, not per-request.
75
+ const sensitiveHeaders = leafKeysForSection('header', paths);
76
+ const sensitiveBody = leafKeysForSection('body', paths);
77
+ const sensitiveParams = leafKeysForSection('param', paths);
78
+ const sensitiveResponse = leafKeysForSection('response', paths);
79
+ return {
80
+ onRequest(config) {
81
+ const otelId = generateSpanId();
82
+ const method = (config.method ?? 'GET').toUpperCase();
83
+ const url = config.url ?? '';
84
+
85
+ // Capture parent context NOW by value — concurrent-safe.
86
+ const currentSpan = spanContext.current();
87
+ const parent = currentSpan?.traceId && currentSpan?.spanId ? {
88
+ traceId: currentSpan.traceId,
89
+ spanId: currentSpan.spanId
90
+ } : null;
91
+ const span = tracer.startSpan(`http.${method} ${url}`, {
92
+ kind: 'CLIENT',
93
+ parent,
94
+ attributes: {
95
+ [ATTR_HTTP_REQUEST_METHOD]: method,
96
+ // 'http.request.method'
97
+ 'http.url': url // stable experimental, no change
98
+ }
99
+ });
100
+
101
+ // Request headers
102
+ if (config.headers) {
103
+ const redacted = redactObject(config.headers, sensitiveHeaders);
104
+ const serialized = toJsonAttr(redacted);
105
+ if (serialized) span.setAttribute('http.request.headers', serialized);
106
+ }
107
+
108
+ // Query params
109
+ if (config.params) {
110
+ const redacted = redactObject(config.params, sensitiveParams);
111
+ const serialized = toJsonAttr(redacted);
112
+ if (serialized) span.setAttribute('http.request.params', serialized);
113
+ }
114
+
115
+ // Request body
116
+ const reqBody = normalizeBody(config.data);
117
+ if (reqBody) {
118
+ const redacted = redactObject(reqBody, sensitiveBody);
119
+ const serialized = toJsonAttr(redacted);
120
+ if (serialized) span.setAttribute('http.request.body', serialized);
121
+ }
122
+ activeNetworkSpans.set(otelId, span);
123
+ config.__otelId = otelId;
124
+ return config;
125
+ },
126
+ onResponse(response) {
127
+ const otelId = response.config.__otelId;
128
+ if (otelId) {
129
+ const span = activeNetworkSpans.get(otelId);
130
+ if (span) {
131
+ span.setAttribute(ATTR_HTTP_RESPONSE_STATUS_CODE, response.status);
132
+
133
+ // Response headers
134
+ if (response.headers) {
135
+ const redacted = redactObject(response.headers, sensitiveHeaders);
136
+ const serialized = toJsonAttr(redacted);
137
+ if (serialized) span.setAttribute('http.response.headers', serialized);
138
+ }
139
+
140
+ // Response body
141
+ const resBody = normalizeBody(response.data);
142
+ if (resBody) {
143
+ const redacted = redactObject(resBody, sensitiveResponse);
144
+ const serialized = toJsonAttr(redacted);
145
+ if (serialized) span.setAttribute('http.response.body', serialized);
146
+ }
147
+ span.setStatus('OK');
148
+ span.end();
149
+ activeNetworkSpans.delete(otelId);
150
+ }
151
+ }
152
+ return response;
153
+ },
154
+ onError(error) {
155
+ const otelId = error.config?.__otelId;
156
+ if (otelId) {
157
+ const span = activeNetworkSpans.get(otelId);
158
+ if (span) {
159
+ span.setAttribute(ATTR_HTTP_RESPONSE_STATUS_CODE, error.response?.status ?? 0);
160
+
161
+ // Error response headers + body when available
162
+ if (error.response?.headers) {
163
+ const redacted = redactObject(error.response.headers, sensitiveHeaders);
164
+ const serialized = toJsonAttr(redacted);
165
+ if (serialized) span.setAttribute('http.response.headers', serialized);
166
+ }
167
+ const errBody = normalizeBody(error.response?.data);
168
+ if (errBody) {
169
+ const redacted = redactObject(errBody, sensitiveResponse);
170
+ const serialized = toJsonAttr(redacted);
171
+ if (serialized) span.setAttribute('http.response.body', serialized);
172
+ }
173
+ span.recordException(error);
174
+ span.setStatus('ERROR', error.message);
175
+ span.end();
176
+ activeNetworkSpans.delete(otelId);
177
+ }
178
+ }
179
+ return Promise.reject(error);
180
+ }
181
+ };
182
+ }
183
+ //# sourceMappingURL=network.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["ATTR_HTTP_REQUEST_METHOD","ATTR_HTTP_RESPONSE_STATUS_CODE","spanContext","generateSpanId","activeNetworkSpans","Map","leafKeysForSection","section","paths","prefix","result","Set","path","toLowerCase","startsWith","add","slice","length","redactObject","obj","sensitive","size","key","Object","keys","has","normalizeBody","data","undefined","Array","isArray","parsed","JSON","parse","toJsonAttr","stringify","createAxiosInstrumentation","tracer","options","sensitiveKeys","map","k","sensitiveHeaders","sensitiveBody","sensitiveParams","sensitiveResponse","onRequest","config","otelId","method","toUpperCase","url","currentSpan","current","parent","traceId","spanId","span","startSpan","kind","attributes","headers","redacted","serialized","setAttribute","params","reqBody","set","__otelId","onResponse","response","get","status","resBody","setStatus","end","delete","onError","error","errBody","recordException","message","Promise","reject"],"sourceRoot":"../../../src","sources":["instrumentation/network.ts"],"mappings":";;AAAA,SACEA,wBAAwB,EACxBC,8BAA8B,QACzB,qCAAqC;AAE5C,SAASC,WAAW,QAAQ,4BAAyB;AACrD,SAASC,cAAc,QAAQ,gBAAa;AAI5C;AACA,MAAMC,kBAAkB,GAAG,IAAIC,GAAG,CAA0B,CAAC;;AAE7D;;AA2BA;;AAEA;AACA;AACA;AACA,SAASC,kBAAkBA,CAACC,OAAe,EAAEC,KAAe,EAAe;EACzE,MAAMC,MAAM,GAAG,GAAGF,OAAO,GAAG;EAC5B,MAAMG,MAAM,GAAG,IAAIC,GAAG,CAAS,CAAC;EAChC,KAAK,MAAMC,IAAI,IAAIJ,KAAK,EAAE;IACxB,IAAII,IAAI,CAACC,WAAW,CAAC,CAAC,CAACC,UAAU,CAACL,MAAM,CAAC,EAAE;MACzCC,MAAM,CAACK,GAAG,CAACH,IAAI,CAACI,KAAK,CAACP,MAAM,CAACQ,MAAM,CAAC,CAACJ,WAAW,CAAC,CAAC,CAAC;IACrD;EACF;EACA,OAAOH,MAAM;AACf;;AAEA;AACA;AACA;AACA,SAASQ,YAAYA,CACnBC,GAA4B,EAC5BC,SAAsB,EACG;EACzB,IAAIA,SAAS,CAACC,IAAI,KAAK,CAAC,EAAE,OAAOF,GAAG;EACpC,MAAMT,MAA+B,GAAG,CAAC,CAAC;EAC1C,KAAK,MAAMY,GAAG,IAAIC,MAAM,CAACC,IAAI,CAACL,GAAG,CAAC,EAAE;IACl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iBAAiB,CAAC;YACzD,MAAMkB,UAAU,GAAG7B,UAAU,CAAC4B,QAAQ,CAAC;YACvC,IAAIC,UAAU,EAAEN,IAAI,CAACO,YAAY,CAAC,oBAAoB,EAAED,UAAU,CAAC;UACrE;UAEAN,IAAI,CAACuB,eAAe,CAACF,KAAyB,CAAC;UAC/CrB,IAAI,CAACiB,SAAS,CAAC,OAAO,EAAEI,KAAK,CAACG,OAAO,CAAC;UACtCxB,IAAI,CAACkB,GAAG,CAAC,CAAC;UACVvE,kBAAkB,CAACwE,MAAM,CAAC5B,MAAM,CAAC;QACnC;MACF;MACA,OAAOkC,OAAO,CAACC,MAAM,CAACL,KAAK,CAAC;IAC9B;EACF,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+
3
+ import React, { createContext, Component } from 'react';
4
+ import { otel } from "../sdk.js";
5
+ import { jsx as _jsx } from "react/jsx-runtime";
6
+ export const OtelContext = /*#__PURE__*/createContext(undefined);
7
+ class OtelErrorBoundary extends Component {
8
+ constructor(props) {
9
+ super(props);
10
+ this.state = {
11
+ hasError: false
12
+ };
13
+ }
14
+ static getDerivedStateFromError() {
15
+ return {
16
+ hasError: true
17
+ };
18
+ }
19
+ componentDidCatch(error, _info) {
20
+ this.props.tracer.recordException(error, {
21
+ 'error.source': 'react_error_boundary'
22
+ });
23
+ }
24
+ render() {
25
+ if (this.state.hasError) {
26
+ return null;
27
+ }
28
+ return this.props.children;
29
+ }
30
+ }
31
+ export function OtelProvider({
32
+ children,
33
+ withErrorBoundary = false
34
+ }) {
35
+ const tracer = otel.getTracer();
36
+ const meter = otel.getMeter();
37
+ const logger = otel.getLogger();
38
+ const value = {
39
+ tracer,
40
+ meter,
41
+ logger,
42
+ recordEvent: (name, attributes) => tracer.recordEvent(name, attributes),
43
+ setUser: user => otel.setUser(user)
44
+ };
45
+ const content = /*#__PURE__*/_jsx(OtelContext.Provider, {
46
+ value: value,
47
+ children: children
48
+ });
49
+ if (withErrorBoundary) {
50
+ return /*#__PURE__*/_jsx(OtelErrorBoundary, {
51
+ tracer: tracer,
52
+ children: content
53
+ });
54
+ }
55
+ return content;
56
+ }
57
+ //# sourceMappingURL=OtelProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","createContext","Component","otel","jsx","_jsx","OtelContext","undefined","OtelErrorBoundary","constructor","props","state","hasError","getDerivedStateFromError","componentDidCatch","error","_info","tracer","recordException","render","children","OtelProvider","withErrorBoundary","getTracer","meter","getMeter","logger","getLogger","value","recordEvent","name","attributes","setUser","user","content","Provider"],"sourceRoot":"../../../src","sources":["react/OtelProvider.tsx"],"mappings":";;AAAA,OAAOA,KAAK,IACVC,aAAa,EACbC,SAAS,QAGJ,OAAO;AAKd,SAASC,IAAI,QAAQ,WAAQ;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAU9B,OAAO,MAAMC,WAAW,gBAAGL,aAAa,CACtCM,SACF,CAAC;AAWD,MAAMC,iBAAiB,SAASN,SAAS,CAGvC;EACAO,WAAWA,CAACC,KAAyB,EAAE;IACrC,KAAK,CAACA,KAAK,CAAC;IACZ,IAAI,CAACC,KAAK,GAAG;MAAEC,QAAQ,EAAE;IAAM,CAAC;EAClC;EAEA,OAAOC,wBAAwBA,CAAA,EAAuB;IACpD,OAAO;MAAED,QAAQ,EAAE;IAAK,CAAC;EAC3B;EAEAE,iBAAiBA,CAACC,KAAY,EAAEC,KAAgB,EAAQ;IACtD,IAAI,CAACN,KAAK,CAACO,MAAM,CAACC,eAAe,CAACH,KAAK,EAAE;MACvC,cAAc,EAAE;IAClB,CAAC,CAAC;EACJ;EAEAI,MAAMA,CAAA,EAAc;IAClB,IAAI,IAAI,CAACR,KAAK,CAACC,QAAQ,EAAE;MACvB,OAAO,IAAI;IACb;IACA,OAAO,IAAI,CAACF,KAAK,CAACU,QAAQ;EAC5B;AACF;AAOA,OAAO,SAASC,YAAYA,CAAC;EAC3BD,QAAQ;EACRE,iBAAiB,GAAG;AACH,CAAC,EAAsB;EACxC,MAAML,MAAM,GAAGd,IAAI,CAACoB,SAAS,CAAC,CAAC;EAC/B,MAAMC,KAAK,GAAGrB,IAAI,CAACsB,QAAQ,CAAC,CAAC;EAC7B,MAAMC,MAAM,GAAGvB,IAAI,CAACwB,SAAS,CAAC,CAAC;EAE/B,MAAMC,KAAuB,GAAG;IAC9BX,MAAM;IACNO,KAAK;IACLE,MAAM;IACNG,WAAW,EAAEA,CAACC,IAAI,EAAEC,UAAU,KAC5Bd,MAAM,CAACY,WAAW,CAChBC,IAAI,EACJC,UAIF,CAAC;IACHC,OAAO,EAAGC,IAAI,IAAK9B,IAAI,CAAC6B,OAAO,CAACC,IAAI;EACtC,CAAC;EAED,MAAMC,OAAO,gBACX7B,IAAA,CAACC,WAAW,CAAC6B,QAAQ;IAACP,KAAK,EAAEA,KAAM;IAAAR,QAAA,EAAEA;EAAQ,CAAuB,CACrE;EAED,IAAIE,iBAAiB,EAAE;IACrB,oBAAOjB,IAAA,CAACG,iBAAiB;MAACS,MAAM,EAAEA,MAAO;MAAAG,QAAA,EAAEc;IAAO,CAAoB,CAAC;EACzE;EAEA,OAAOA,OAAO;AAChB","ignoreList":[]}
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ import { useContext } from 'react';
4
+ import { OtelContext } from "./OtelProvider.js";
5
+ export function useOtel() {
6
+ const ctx = useContext(OtelContext);
7
+ if (!ctx) {
8
+ throw new Error('[react-native-otel] useOtel must be used inside OtelProvider.');
9
+ }
10
+ return ctx;
11
+ }
12
+ //# sourceMappingURL=useOtel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useContext","OtelContext","useOtel","ctx","Error"],"sourceRoot":"../../../src","sources":["react/useOtel.ts"],"mappings":";;AAAA,SAASA,UAAU,QAAQ,OAAO;AAGlC,SAASC,WAAW,QAAQ,mBAAgB;AAE5C,OAAO,SAASC,OAAOA,CAAA,EAAqB;EAC1C,MAAMC,GAAG,GAAGH,UAAU,CAACC,WAAW,CAAC;EACnC,IAAI,CAACE,GAAG,EAAE;IACR,MAAM,IAAIC,KAAK,CACb,+DACF,CAAC;EACH;EACA,OAAOD,GAAG;AACZ","ignoreList":[]}
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+
3
+ import { spanContext } from "./context/span-context.js";
4
+ import { setMaxStringLength } from "./core/attributes.js";
5
+ import { OtelLogger } from "./core/log-record.js";
6
+ import { Meter } from "./core/meter.js";
7
+ import { buildResource } from "./core/resource.js";
8
+ import { Tracer } from "./core/tracer.js";
9
+ import { installErrorInstrumentation } from "./instrumentation/errors.js";
10
+ import { installLifecycleInstrumentation } from "./instrumentation/lifecycle.js";
11
+ class OtelSDK {
12
+ userAttributes_ = {};
13
+ sensitiveKeys_ = [];
14
+ initialized = false;
15
+ init(config) {
16
+ if (this.initialized) return;
17
+ this.initialized = true;
18
+ if (config.maxAttributeStringLength !== undefined) {
19
+ setMaxStringLength(config.maxAttributeStringLength);
20
+ }
21
+ this.sensitiveKeys_ = config.sensitiveKeys ?? [];
22
+ this.exporter_ = config.exporter;
23
+ this.metricExporter_ = config.metricExporter;
24
+ this.logExporter_ = config.logExporter;
25
+ this.resource_ = buildResource({
26
+ serviceName: config.serviceName,
27
+ serviceVersion: config.serviceVersion ?? '0.0.0',
28
+ osName: config.osName ?? '',
29
+ osVersion: config.osVersion ?? '',
30
+ deviceBrand: config.deviceBrand ?? '',
31
+ deviceModel: config.deviceModel ?? '',
32
+ deviceType: config.deviceType ?? '',
33
+ appBuild: config.appBuild ?? '',
34
+ environment: config.environment ?? 'production'
35
+ });
36
+
37
+ // If any exporter supports resource injection (e.g. OtlpHttp*Exporter),
38
+ // hand it the resource so it can include it in OTLP payloads.
39
+ const injectResource = exp => {
40
+ if (exp && typeof exp === 'object' && 'setResource' in exp) {
41
+ exp.setResource(this.resource_);
42
+ }
43
+ };
44
+ injectResource(config.exporter);
45
+ injectResource(config.metricExporter);
46
+ injectResource(config.logExporter);
47
+ this.tracer_ = new Tracer({
48
+ exporter: config.exporter,
49
+ sampleRate: config.sampleRate,
50
+ getUserAttributes: () => ({
51
+ ...this.userAttributes_
52
+ })
53
+ });
54
+ this.meter_ = new Meter(config.metricExporter);
55
+ this.logger_ = new OtelLogger(config.logExporter);
56
+
57
+ // Check for pending crash span and install global error handler
58
+ installErrorInstrumentation({
59
+ tracer: this.tracer_,
60
+ storage: config.storage,
61
+ exporter: config.exporter
62
+ });
63
+
64
+ // Install lifecycle instrumentation
65
+ installLifecycleInstrumentation(this.meter_);
66
+ }
67
+
68
+ // Records a named event on the current screen span.
69
+ // Safe to call before init() — silently no-ops if SDK is not yet initialized.
70
+ recordEvent(name, properties) {
71
+ this.tracer_?.recordEvent(name, properties);
72
+ }
73
+ setUser(user) {
74
+ this.userAttributes_ = {
75
+ ...(user.id ? {
76
+ 'user.id': user.id
77
+ } : {}),
78
+ ...(user.email ? {
79
+ 'user.email': user.email
80
+ } : {})
81
+ };
82
+ }
83
+ getTracer() {
84
+ if (!this.tracer_) {
85
+ throw new Error('[react-native-otel] SDK not initialized. Call otel.init() first.');
86
+ }
87
+ return this.tracer_;
88
+ }
89
+ getMeter() {
90
+ if (!this.meter_) {
91
+ throw new Error('[react-native-otel] SDK not initialized. Call otel.init() first.');
92
+ }
93
+ return this.meter_;
94
+ }
95
+ getSensitiveKeys() {
96
+ return this.sensitiveKeys_;
97
+ }
98
+ getLogger() {
99
+ if (!this.logger_) {
100
+ throw new Error('[react-native-otel] SDK not initialized. Call otel.init() first.');
101
+ }
102
+ return this.logger_;
103
+ }
104
+ async shutdown() {
105
+ // End active screen span
106
+ const current = spanContext.current();
107
+ if (current) {
108
+ current.end();
109
+ spanContext.setCurrent(undefined);
110
+ }
111
+
112
+ // Flush buffered metrics
113
+ this.meter_?.flush();
114
+
115
+ // Flush + tear down exporter timers (e.g. OtlpHttp*Exporter)
116
+ const destroyExporter = exp => {
117
+ if (exp && typeof exp === 'object' && 'destroy' in exp) {
118
+ exp.destroy();
119
+ }
120
+ };
121
+ destroyExporter(this.exporter_);
122
+ destroyExporter(this.metricExporter_);
123
+ destroyExporter(this.logExporter_);
124
+ }
125
+ }
126
+ export const otel = new OtelSDK();
127
+ //# sourceMappingURL=sdk.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["spanContext","setMaxStringLength","OtelLogger","Meter","buildResource","Tracer","installErrorInstrumentation","installLifecycleInstrumentation","OtelSDK","userAttributes_","sensitiveKeys_","initialized","init","config","maxAttributeStringLength","undefined","sensitiveKeys","exporter_","exporter","metricExporter_","metricExporter","logExporter_","logExporter","resource_","serviceName","serviceVersion","osName","osVersion","deviceBrand","deviceModel","deviceType","appBuild","environment","injectResource","exp","setResource","tracer_","sampleRate","getUserAttributes","meter_","logger_","tracer","storage","recordEvent","name","properties","setUser","user","id","email","getTracer","Error","getMeter","getSensitiveKeys","getLogger","shutdown","current","end","setCurrent","flush","destroyExporter","destroy","otel"],"sourceRoot":"../../src","sources":["sdk.ts"],"mappings":";;AAQA,SAASA,WAAW,QAAQ,2BAAwB;AACpD,SAASC,kBAAkB,QAAQ,sBAAmB;AACtD,SAASC,UAAU,QAAQ,sBAAmB;AAC9C,SAASC,KAAK,QAAQ,iBAAc;AACpC,SAASC,aAAa,QAAQ,oBAAiB;AAC/C,SAASC,MAAM,QAAQ,kBAAe;AACtC,SAASC,2BAA2B,QAAQ,6BAA0B;AACtE,SAASC,+BAA+B,QAAQ,gCAA6B;AA0B7E,MAAMC,OAAO,CAAC;EACJC,eAAe,GAAe,CAAC,CAAC;EAQhCC,cAAc,GAAa,EAAE;EAC7BC,WAAW,GAAG,KAAK;EAE3BC,IAAIA,CAACC,MAAkB,EAAQ;IAC7B,IAAI,IAAI,CAACF,WAAW,EAAE;IACtB,IAAI,CAACA,WAAW,GAAG,IAAI;IAEvB,IAAIE,MAAM,CAACC,wBAAwB,KAAKC,SAAS,EAAE;MACjDd,kBAAkB,CAACY,MAAM,CAACC,wBAAwB,CAAC;IACrD;IAEA,IAAI,CAACJ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AASA,CAAA,EAAe;IACtB,IAAI,CAAC,IAAI,CAACd,OAAO,EAAE;MACjB,MAAM,IAAIW,KAAK,CACb,kEACF,CAAC;IACH;IACA,OAAO,IAAI,CAACX,OAAO;EACrB;EAEA,MAAMe,QAAQA,CAAA,EAAkB;IAC9B;IACA,MAAMC,OAAO,GAAGxD,WAAW,CAACwD,OAAO,CAAC,CAAC;IACrC,IAAIA,OAAO,EAAE;MACXA,OAAO,CAACC,GAAG,CAAC,CAAC;MACbzD,WAAW,CAAC0D,UAAU,CAAC3C,SAAS,CAAC;IACnC;;IAEA;IACA,IAAI,CAACwB,MAAM,EAAEoB,KAAK,CAAC,CAAC;;IAEpB;IACA,MAAMC,eAAe,GAAI1B,GAAY,IAAK;MACxC,IAAIA,GAAG,IAAI,OAAOA,GAAG,KAAK,QAAQ,IAAI,SAAS,IAAIA,GAAG,EAAE;QACrDA,GAAG,CAAyB2B,OAAO,CAAC,CAAC;MACxC;IACF,CAAC;IACDD,eAAe,CAAC,IAAI,CAAC3C,SAAS,CAAC;IAC/B2C,eAAe,CAAC,IAAI,CAACzC,eAAe,CAAC;IACrCyC,eAAe,CAAC,IAAI,CAACvC,YAAY,CAAC;EACpC;AACF;AAEA,OAAO,MAAMyC,IAAI,GAAG,IAAItD,OAAO,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"type":"module"}
@@ -0,0 +1,9 @@
1
+ import { Span, NoopSpan } from '../core/span';
2
+ declare class SpanContextManager {
3
+ private current_;
4
+ setCurrent(span: Span | NoopSpan | undefined): void;
5
+ current(): Span | NoopSpan | undefined;
6
+ }
7
+ export declare const spanContext: SpanContextManager;
8
+ export {};
9
+ //# sourceMappingURL=span-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"span-context.d.ts","sourceRoot":"","sources":["../../../../src/context/span-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAI9C,cAAM,kBAAkB;IACtB,OAAO,CAAC,QAAQ,CAA8B;IAE9C,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,QAAQ,GAAG,SAAS,GAAG,IAAI;IAInD,OAAO,IAAI,IAAI,GAAG,QAAQ,GAAG,SAAS;CAGvC;AAED,eAAO,MAAM,WAAW,oBAA2B,CAAC"}
@@ -0,0 +1,6 @@
1
+ export declare function setMaxStringLength(length: number): void;
2
+ export type AttributeValue = string | number | boolean | string[] | number[] | boolean[];
3
+ export type Attributes = Record<string, AttributeValue>;
4
+ export declare function sanitizeValue(value: unknown): AttributeValue | undefined;
5
+ export declare function sanitizeAttributes(attrs: Attributes | Record<string, unknown>): Attributes;
6
+ //# sourceMappingURL=attributes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attributes.d.ts","sourceRoot":"","sources":["../../../../src/core/attributes.ts"],"names":[],"mappings":"AAEA,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAEvD;AAED,MAAM,MAAM,cAAc,GACtB,MAAM,GACN,MAAM,GACN,OAAO,GACP,MAAM,EAAE,GACR,MAAM,EAAE,GACR,OAAO,EAAE,CAAC;AACd,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;AAKxD,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,cAAc,GAAG,SAAS,CA2BxE;AAID,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC1C,UAAU,CASZ"}
@@ -0,0 +1,2 @@
1
+ export declare function now(): number;
2
+ //# sourceMappingURL=clock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clock.d.ts","sourceRoot":"","sources":["../../../../src/core/clock.ts"],"names":[],"mappings":"AAEA,wBAAgB,GAAG,IAAI,MAAM,CAE5B"}
@@ -0,0 +1,3 @@
1
+ export declare function generateTraceId(): string;
2
+ export declare function generateSpanId(): string;
3
+ //# sourceMappingURL=ids.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ids.d.ts","sourceRoot":"","sources":["../../../../src/core/ids.ts"],"names":[],"mappings":"AAQA,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAED,wBAAgB,cAAc,IAAI,MAAM,CAEvC"}
@@ -0,0 +1,15 @@
1
+ import type { Attributes } from './attributes';
2
+ import type { LogExporter } from '../exporters/types';
3
+ export type LogSeverity = 'TRACE' | 'DEBUG' | 'INFO' | 'WARN' | 'ERROR' | 'FATAL';
4
+ export declare class OtelLogger {
5
+ private exporter;
6
+ constructor(exporter?: LogExporter);
7
+ private emit;
8
+ trace(body: string, attrs?: Attributes): void;
9
+ debug(body: string, attrs?: Attributes): void;
10
+ info(body: string, attrs?: Attributes): void;
11
+ warn(body: string, attrs?: Attributes): void;
12
+ error(body: string, attrs?: Attributes): void;
13
+ fatal(body: string, attrs?: Attributes): void;
14
+ }
15
+ //# sourceMappingURL=log-record.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log-record.d.ts","sourceRoot":"","sources":["../../../../src/core/log-record.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAa,MAAM,oBAAoB,CAAC;AAKjE,MAAM,MAAM,WAAW,GACnB,OAAO,GACP,OAAO,GACP,MAAM,GACN,MAAM,GACN,OAAO,GACP,OAAO,CAAC;AAEZ,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAA0B;gBAE9B,QAAQ,CAAC,EAAE,WAAW;IAIlC,OAAO,CAAC,IAAI;IAaZ,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,UAAU,GAAG,IAAI;IAI7C,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,UAAU,GAAG,IAAI;IAI7C,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,UAAU,GAAG,IAAI;IAI5C,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,UAAU,GAAG,IAAI;IAI5C,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,UAAU,GAAG,IAAI;IAI7C,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,UAAU,GAAG,IAAI;CAG9C"}
@@ -0,0 +1,30 @@
1
+ import type { Attributes } from './attributes';
2
+ import type { MetricExporter, MetricRecord } from '../exporters/types';
3
+ export declare class Counter {
4
+ private name;
5
+ private pushToBuffer;
6
+ constructor(name: string, pushToBuffer: (record: MetricRecord) => void);
7
+ add(value: number, attrs?: Attributes): void;
8
+ }
9
+ export declare class Histogram {
10
+ private name;
11
+ private pushToBuffer;
12
+ constructor(name: string, pushToBuffer: (record: MetricRecord) => void);
13
+ record(value: number, attrs?: Attributes): void;
14
+ }
15
+ export declare class Gauge {
16
+ private name;
17
+ private pushToBuffer;
18
+ constructor(name: string, pushToBuffer: (record: MetricRecord) => void);
19
+ set(value: number, attrs?: Attributes): void;
20
+ }
21
+ export declare class Meter {
22
+ private buffer;
23
+ private exporter;
24
+ constructor(exporter?: MetricExporter);
25
+ createCounter(name: string): Counter;
26
+ createHistogram(name: string): Histogram;
27
+ createGauge(name: string): Gauge;
28
+ flush(): void;
29
+ }
30
+ //# sourceMappingURL=meter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"meter.d.ts","sourceRoot":"","sources":["../../../../src/core/meter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAIvE,qBAAa,OAAO;IAEhB,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,YAAY;gBADZ,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,IAAI;IAGtD,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,UAAU,GAAG,IAAI;CAS7C;AAED,qBAAa,SAAS;IAElB,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,YAAY;gBADZ,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,IAAI;IAGtD,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,UAAU,GAAG,IAAI;CAShD;AAED,qBAAa,KAAK;IAEd,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,YAAY;gBADZ,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,IAAI;IAGtD,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,UAAU,GAAG,IAAI;CAS7C;AAED,qBAAa,KAAK;IAChB,OAAO,CAAC,MAAM,CAAsB;IACpC,OAAO,CAAC,QAAQ,CAA6B;gBAEjC,QAAQ,CAAC,EAAE,cAAc;IAIrC,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIpC,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS;IAIxC,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK;IAIhC,KAAK,IAAI,IAAI;CAKd"}
@@ -0,0 +1,25 @@
1
+ import { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION } from '@opentelemetry/semantic-conventions';
2
+ import { ATTR_APP_BUILD_ID, ATTR_DEPLOYMENT_ENVIRONMENT_NAME, ATTR_DEVICE_MANUFACTURER, ATTR_DEVICE_MODEL_NAME, ATTR_OS_NAME, ATTR_OS_VERSION } from '@opentelemetry/semantic-conventions/incubating';
3
+ export interface Resource {
4
+ [ATTR_SERVICE_NAME]: string;
5
+ [ATTR_SERVICE_VERSION]: string;
6
+ [ATTR_OS_NAME]: string;
7
+ [ATTR_OS_VERSION]: string;
8
+ [ATTR_DEVICE_MANUFACTURER]: string;
9
+ [ATTR_DEVICE_MODEL_NAME]: string;
10
+ 'device.type': string | number;
11
+ [ATTR_APP_BUILD_ID]: string;
12
+ [ATTR_DEPLOYMENT_ENVIRONMENT_NAME]: string;
13
+ }
14
+ export declare function buildResource(params: {
15
+ serviceName: string;
16
+ serviceVersion: string;
17
+ osName: string;
18
+ osVersion: string;
19
+ deviceBrand: string;
20
+ deviceModel: string;
21
+ deviceType: string | number;
22
+ appBuild: string;
23
+ environment: string;
24
+ }): Readonly<Resource>;
25
+ //# sourceMappingURL=resource.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resource.d.ts","sourceRoot":"","sources":["../../../../src/core/resource.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACrB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACL,iBAAiB,EACjB,gCAAgC,EAChC,wBAAwB,EACxB,sBAAsB,EACtB,YAAY,EACZ,eAAe,EAChB,MAAM,gDAAgD,CAAC;AAExD,MAAM,WAAW,QAAQ;IACvB,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC5B,CAAC,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC/B,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IACvB,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAC1B,CAAC,wBAAwB,CAAC,EAAE,MAAM,CAAC;IACnC,CAAC,sBAAsB,CAAC,EAAE,MAAM,CAAC;IACjC,aAAa,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC5B,CAAC,gCAAgC,CAAC,EAAE,MAAM,CAAC;CAC5C;AAID,wBAAgB,aAAa,CAAC,MAAM,EAAE;IACpC,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;CACrB,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAYrB"}
@@ -0,0 +1,77 @@
1
+ import type { Attributes } from './attributes';
2
+ export interface SpanExporter {
3
+ export(spans: ReadonlySpan[]): void;
4
+ }
5
+ export type SpanKind = 'INTERNAL' | 'CLIENT' | 'SERVER' | 'PRODUCER' | 'CONSUMER';
6
+ export type SpanStatus = 'UNSET' | 'OK' | 'ERROR';
7
+ export interface SpanEvent {
8
+ name: string;
9
+ timestampMs: number;
10
+ attributes: Attributes;
11
+ }
12
+ export interface ReadonlySpan {
13
+ readonly traceId: string;
14
+ readonly spanId: string;
15
+ readonly parentSpanId: string | undefined;
16
+ readonly name: string;
17
+ readonly kind: SpanKind;
18
+ readonly startTimeMs: number;
19
+ readonly endTimeMs: number | undefined;
20
+ readonly attributes: Readonly<Attributes>;
21
+ readonly events: readonly SpanEvent[];
22
+ readonly droppedEventsCount: number;
23
+ readonly status: SpanStatus;
24
+ readonly statusMessage: string | undefined;
25
+ }
26
+ export interface SpanContext {
27
+ traceId: string;
28
+ spanId: string;
29
+ }
30
+ export declare class Span implements ReadonlySpan {
31
+ private static readonly MAX_EVENTS;
32
+ readonly traceId: string;
33
+ readonly spanId: string;
34
+ readonly parentSpanId: string | undefined;
35
+ readonly name: string;
36
+ readonly kind: SpanKind;
37
+ readonly startTimeMs: number;
38
+ endTimeMs: number | undefined;
39
+ attributes: Attributes;
40
+ events: SpanEvent[];
41
+ droppedEventsCount: number;
42
+ status: SpanStatus;
43
+ statusMessage: string | undefined;
44
+ private exporter;
45
+ constructor(params: {
46
+ name: string;
47
+ kind?: SpanKind;
48
+ attributes?: Attributes;
49
+ parent?: SpanContext;
50
+ exporter?: SpanExporter;
51
+ });
52
+ setAttribute(key: string, value: Attributes[string]): void;
53
+ addEvent(name: string, attrs?: Attributes): void;
54
+ setStatus(status: SpanStatus, message?: string): void;
55
+ recordException(error: Error, attrs?: Attributes): void;
56
+ end(): void;
57
+ }
58
+ export declare class NoopSpan implements ReadonlySpan {
59
+ readonly traceId = "";
60
+ readonly spanId = "";
61
+ readonly parentSpanId: undefined;
62
+ readonly name = "";
63
+ readonly kind: SpanKind;
64
+ readonly startTimeMs = 0;
65
+ readonly endTimeMs: undefined;
66
+ readonly attributes: {};
67
+ readonly events: SpanEvent[];
68
+ readonly droppedEventsCount = 0;
69
+ readonly status: SpanStatus;
70
+ readonly statusMessage: undefined;
71
+ setAttribute(_key: string, _value: Attributes[string]): void;
72
+ addEvent(_name: string, _attrs?: Attributes): void;
73
+ setStatus(_status: SpanStatus, _message?: string): void;
74
+ recordException(_error: Error, _attrs?: Attributes): void;
75
+ end(): void;
76
+ }
77
+ //# sourceMappingURL=span.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"span.d.ts","sourceRoot":"","sources":["../../../../src/core/span.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAM/C,MAAM,WAAW,YAAY;IAC3B,MAAM,CAAC,KAAK,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC;CACrC;AAED,MAAM,MAAM,QAAQ,GAChB,UAAU,GACV,QAAQ,GACR,QAAQ,GACR,UAAU,GACV,UAAU,CAAC;AACf,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,IAAI,GAAG,OAAO,CAAC;AAElD,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,UAAU,CAAC;CACxB;AAED,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,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