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.
- package/LICENSE +20 -0
- package/README.md +37 -0
- package/lib/module/context/span-context.js +14 -0
- package/lib/module/context/span-context.js.map +1 -0
- package/lib/module/core/attributes.js +43 -0
- package/lib/module/core/attributes.js.map +1 -0
- package/lib/module/core/clock.js +8 -0
- package/lib/module/core/clock.js.map +1 -0
- package/lib/module/core/ids.js +16 -0
- package/lib/module/core/ids.js.map +1 -0
- package/lib/module/core/log-record.js +41 -0
- package/lib/module/core/log-record.js.map +1 -0
- package/lib/module/core/meter.js +70 -0
- package/lib/module/core/meter.js.map +1 -0
- package/lib/module/core/resource.js +20 -0
- package/lib/module/core/resource.js.map +1 -0
- package/lib/module/core/span.js +96 -0
- package/lib/module/core/span.js.map +1 -0
- package/lib/module/core/tracer.js +48 -0
- package/lib/module/core/tracer.js.map +1 -0
- package/lib/module/exporters/console-exporter.js +53 -0
- package/lib/module/exporters/console-exporter.js.map +1 -0
- package/lib/module/exporters/otlp-http-exporter.js +317 -0
- package/lib/module/exporters/otlp-http-exporter.js.map +1 -0
- package/lib/module/exporters/types.js +4 -0
- package/lib/module/exporters/types.js.map +1 -0
- package/lib/module/index.js +24 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/instrumentation/errors.js +63 -0
- package/lib/module/instrumentation/errors.js.map +1 -0
- package/lib/module/instrumentation/lifecycle.js +15 -0
- package/lib/module/instrumentation/lifecycle.js.map +1 -0
- package/lib/module/instrumentation/navigation.js +51 -0
- package/lib/module/instrumentation/navigation.js.map +1 -0
- package/lib/module/instrumentation/network.js +183 -0
- package/lib/module/instrumentation/network.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/react/OtelProvider.js +57 -0
- package/lib/module/react/OtelProvider.js.map +1 -0
- package/lib/module/react/useOtel.js +12 -0
- package/lib/module/react/useOtel.js.map +1 -0
- package/lib/module/sdk.js +127 -0
- package/lib/module/sdk.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/context/span-context.d.ts +9 -0
- package/lib/typescript/src/context/span-context.d.ts.map +1 -0
- package/lib/typescript/src/core/attributes.d.ts +6 -0
- package/lib/typescript/src/core/attributes.d.ts.map +1 -0
- package/lib/typescript/src/core/clock.d.ts +2 -0
- package/lib/typescript/src/core/clock.d.ts.map +1 -0
- package/lib/typescript/src/core/ids.d.ts +3 -0
- package/lib/typescript/src/core/ids.d.ts.map +1 -0
- package/lib/typescript/src/core/log-record.d.ts +15 -0
- package/lib/typescript/src/core/log-record.d.ts.map +1 -0
- package/lib/typescript/src/core/meter.d.ts +30 -0
- package/lib/typescript/src/core/meter.d.ts.map +1 -0
- package/lib/typescript/src/core/resource.d.ts +25 -0
- package/lib/typescript/src/core/resource.d.ts.map +1 -0
- package/lib/typescript/src/core/span.d.ts +77 -0
- package/lib/typescript/src/core/span.d.ts.map +1 -0
- package/lib/typescript/src/core/tracer.d.ts +21 -0
- package/lib/typescript/src/core/tracer.d.ts.map +1 -0
- package/lib/typescript/src/exporters/console-exporter.d.ts +17 -0
- package/lib/typescript/src/exporters/console-exporter.d.ts.map +1 -0
- package/lib/typescript/src/exporters/otlp-http-exporter.d.ts +58 -0
- package/lib/typescript/src/exporters/otlp-http-exporter.d.ts.map +1 -0
- package/lib/typescript/src/exporters/types.d.ts +25 -0
- package/lib/typescript/src/exporters/types.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +25 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/instrumentation/errors.d.ts +15 -0
- package/lib/typescript/src/instrumentation/errors.d.ts.map +1 -0
- package/lib/typescript/src/instrumentation/lifecycle.d.ts +3 -0
- package/lib/typescript/src/instrumentation/lifecycle.d.ts.map +1 -0
- package/lib/typescript/src/instrumentation/navigation.d.ts +7 -0
- package/lib/typescript/src/instrumentation/navigation.d.ts.map +1 -0
- package/lib/typescript/src/instrumentation/network.d.ts +33 -0
- package/lib/typescript/src/instrumentation/network.d.ts.map +1 -0
- package/lib/typescript/src/react/OtelProvider.d.ts +21 -0
- package/lib/typescript/src/react/OtelProvider.d.ts.map +1 -0
- package/lib/typescript/src/react/useOtel.d.ts +3 -0
- package/lib/typescript/src/react/useOtel.d.ts.map +1 -0
- package/lib/typescript/src/sdk.d.ts +50 -0
- package/lib/typescript/src/sdk.d.ts.map +1 -0
- package/package.json +125 -0
- package/src/context/span-context.ts +17 -0
- package/src/core/attributes.ts +61 -0
- package/src/core/clock.ts +5 -0
- package/src/core/ids.ts +15 -0
- package/src/core/log-record.ts +58 -0
- package/src/core/meter.ts +82 -0
- package/src/core/resource.ts +50 -0
- package/src/core/span.ts +161 -0
- package/src/core/tracer.ts +75 -0
- package/src/exporters/console-exporter.ts +89 -0
- package/src/exporters/otlp-http-exporter.ts +377 -0
- package/src/exporters/types.ts +29 -0
- package/src/index.ts +63 -0
- package/src/instrumentation/errors.ts +95 -0
- package/src/instrumentation/lifecycle.ts +17 -0
- package/src/instrumentation/navigation.ts +61 -0
- package/src/instrumentation/network.ts +253 -0
- package/src/react/OtelProvider.tsx +98 -0
- package/src/react/useOtel.ts +14 -0
- package/src/sdk.ts +179 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Attributes } from './attributes';
|
|
2
|
+
import type { SpanContext, SpanExporter, SpanKind } from './span';
|
|
3
|
+
import { Span, NoopSpan } from './span';
|
|
4
|
+
export declare class Tracer {
|
|
5
|
+
private exporter;
|
|
6
|
+
private sampleRate;
|
|
7
|
+
private getUserAttributes;
|
|
8
|
+
constructor(params: {
|
|
9
|
+
exporter?: SpanExporter;
|
|
10
|
+
sampleRate?: number;
|
|
11
|
+
getUserAttributes: () => Attributes;
|
|
12
|
+
});
|
|
13
|
+
startSpan(name: string, options?: {
|
|
14
|
+
kind?: SpanKind;
|
|
15
|
+
attributes?: Attributes;
|
|
16
|
+
parent?: SpanContext | null;
|
|
17
|
+
}): Span | NoopSpan;
|
|
18
|
+
recordEvent(name: string, attributes?: Attributes): void;
|
|
19
|
+
recordException(error: Error, attributes?: Attributes): void;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=tracer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tracer.d.ts","sourceRoot":"","sources":["../../../../src/core/tracer.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAClE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAGxC,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAA2B;IAC3C,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,iBAAiB,CAAmB;gBAEhC,MAAM,EAAE;QAClB,QAAQ,CAAC,EAAE,YAAY,CAAC;QACxB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,iBAAiB,EAAE,MAAM,UAAU,CAAC;KACrC;IAMD,SAAS,CACP,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE;QACR,IAAI,CAAC,EAAE,QAAQ,CAAC;QAChB,UAAU,CAAC,EAAE,UAAU,CAAC;QAIxB,MAAM,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;KAC7B,GACA,IAAI,GAAG,QAAQ;IAqBlB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,UAAU,GAAG,IAAI;IAIxD,eAAe,CAAC,KAAK,EAAE,KAAK,EAAE,UAAU,CAAC,EAAE,UAAU,GAAG,IAAI;CAa7D"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { SpanExporter, MetricExporter, LogExporter, ReadonlySpan, MetricRecord, LogRecord } from './types';
|
|
2
|
+
export declare class ConsoleSpanExporter implements SpanExporter {
|
|
3
|
+
private debug;
|
|
4
|
+
constructor(debug?: boolean);
|
|
5
|
+
export(spans: ReadonlySpan[]): void;
|
|
6
|
+
}
|
|
7
|
+
export declare class ConsoleMetricExporter implements MetricExporter {
|
|
8
|
+
private debug;
|
|
9
|
+
constructor(debug?: boolean);
|
|
10
|
+
export(metrics: MetricRecord[]): void;
|
|
11
|
+
}
|
|
12
|
+
export declare class ConsoleLogExporter implements LogExporter {
|
|
13
|
+
private debug;
|
|
14
|
+
constructor(debug?: boolean);
|
|
15
|
+
export(logs: LogRecord[]): void;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=console-exporter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console-exporter.d.ts","sourceRoot":"","sources":["../../../../src/exporters/console-exporter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,cAAc,EACd,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,SAAS,EACV,MAAM,SAAS,CAAC;AAMjB,qBAAa,mBAAoB,YAAW,YAAY;IAC1C,OAAO,CAAC,KAAK;gBAAL,KAAK,UAAQ;IAEjC,MAAM,CAAC,KAAK,EAAE,YAAY,EAAE,GAAG,IAAI;CAqCpC;AAED,qBAAa,qBAAsB,YAAW,cAAc;IAC9C,OAAO,CAAC,KAAK;gBAAL,KAAK,UAAQ;IAEjC,MAAM,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,IAAI;CAUtC;AAED,qBAAa,kBAAmB,YAAW,WAAW;IACxC,OAAO,CAAC,KAAK;gBAAL,KAAK,UAAQ;IAEjC,MAAM,CAAC,IAAI,EAAE,SAAS,EAAE,GAAG,IAAI;CAehC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { LogExporter, LogRecord, MetricExporter, MetricRecord } from './types';
|
|
2
|
+
import type { Resource } from '../core/resource';
|
|
3
|
+
import type { ReadonlySpan, SpanExporter } from '../core/span';
|
|
4
|
+
export interface OtlpHttpExporterOptions {
|
|
5
|
+
endpoint: string;
|
|
6
|
+
headers?: Record<string, string>;
|
|
7
|
+
batchSize?: number;
|
|
8
|
+
flushIntervalMs?: number;
|
|
9
|
+
}
|
|
10
|
+
export declare class OtlpHttpExporter implements SpanExporter {
|
|
11
|
+
private readonly tracesEndpoint;
|
|
12
|
+
private readonly headers;
|
|
13
|
+
private readonly batchSize;
|
|
14
|
+
private buffer;
|
|
15
|
+
private resource_;
|
|
16
|
+
private timer_;
|
|
17
|
+
constructor(options: OtlpHttpExporterOptions);
|
|
18
|
+
setResource(resource: Readonly<Resource>): void;
|
|
19
|
+
export(spans: ReadonlySpan[]): void;
|
|
20
|
+
flush(): void;
|
|
21
|
+
destroy(): void;
|
|
22
|
+
private send;
|
|
23
|
+
private toOtlpSpan;
|
|
24
|
+
}
|
|
25
|
+
export interface OtlpHttpMetricExporterOptions {
|
|
26
|
+
endpoint: string;
|
|
27
|
+
headers?: Record<string, string>;
|
|
28
|
+
}
|
|
29
|
+
export declare class OtlpHttpMetricExporter implements MetricExporter {
|
|
30
|
+
private readonly metricsEndpoint;
|
|
31
|
+
private readonly headers;
|
|
32
|
+
private resource_;
|
|
33
|
+
constructor(options: OtlpHttpMetricExporterOptions);
|
|
34
|
+
setResource(resource: Readonly<Resource>): void;
|
|
35
|
+
export(metrics: MetricRecord[]): void;
|
|
36
|
+
private send;
|
|
37
|
+
}
|
|
38
|
+
export interface OtlpHttpLogExporterOptions {
|
|
39
|
+
endpoint: string;
|
|
40
|
+
headers?: Record<string, string>;
|
|
41
|
+
batchSize?: number;
|
|
42
|
+
flushIntervalMs?: number;
|
|
43
|
+
}
|
|
44
|
+
export declare class OtlpHttpLogExporter implements LogExporter {
|
|
45
|
+
private readonly logsEndpoint;
|
|
46
|
+
private readonly headers;
|
|
47
|
+
private readonly batchSize;
|
|
48
|
+
private buffer;
|
|
49
|
+
private resource_;
|
|
50
|
+
private timer_;
|
|
51
|
+
constructor(options: OtlpHttpLogExporterOptions);
|
|
52
|
+
setResource(resource: Readonly<Resource>): void;
|
|
53
|
+
export(logs: LogRecord[]): void;
|
|
54
|
+
flush(): void;
|
|
55
|
+
destroy(): void;
|
|
56
|
+
private send;
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=otlp-http-exporter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"otlp-http-exporter.d.ts","sourceRoot":"","sources":["../../../../src/exporters/otlp-http-exporter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,SAAS,EACT,cAAc,EACd,YAAY,EACb,MAAM,SAAS,CAAC;AAEjB,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAuD/D,MAAM,WAAW,uBAAuB;IAEtC,QAAQ,EAAE,MAAM,CAAC;IAEjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEjC,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,qBAAa,gBAAiB,YAAW,YAAY;IACnD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAyB;IACjD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,MAAM,CAAsB;IACpC,OAAO,CAAC,SAAS,CAAiC;IAClD,OAAO,CAAC,MAAM,CAA6C;gBAE/C,OAAO,EAAE,uBAAuB;IAe5C,WAAW,CAAC,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,GAAG,IAAI;IAI/C,MAAM,CAAC,KAAK,EAAE,YAAY,EAAE,GAAG,IAAI;IAOnC,KAAK,IAAI,IAAI;IAOb,OAAO,IAAI,IAAI;IAQf,OAAO,CAAC,IAAI;IA0BZ,OAAO,CAAC,UAAU;CAwBnB;AAOD,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,qBAAa,sBAAuB,YAAW,cAAc;IAC3D,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAS;IACzC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAyB;IACjD,OAAO,CAAC,SAAS,CAAiC;gBAEtC,OAAO,EAAE,6BAA6B;IAQlD,WAAW,CAAC,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,GAAG,IAAI;IAI/C,MAAM,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,IAAI;IAKrC,OAAO,CAAC,IAAI;CAoEb;AAcD,MAAM,WAAW,0BAA0B;IACzC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,qBAAa,mBAAoB,YAAW,WAAW;IACrD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAyB;IACjD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,SAAS,CAAiC;IAClD,OAAO,CAAC,MAAM,CAA6C;gBAE/C,OAAO,EAAE,0BAA0B;IAc/C,WAAW,CAAC,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,GAAG,IAAI;IAI/C,MAAM,CAAC,IAAI,EAAE,SAAS,EAAE,GAAG,IAAI;IAO/B,KAAK,IAAI,IAAI;IAMb,OAAO,IAAI,IAAI;IAQf,OAAO,CAAC,IAAI;CAiCb"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Attributes } from '../core/attributes';
|
|
2
|
+
import type { ReadonlySpan, SpanExporter } from '../core/span';
|
|
3
|
+
export type { ReadonlySpan, SpanExporter };
|
|
4
|
+
export interface MetricRecord {
|
|
5
|
+
type: 'counter' | 'histogram' | 'gauge';
|
|
6
|
+
name: string;
|
|
7
|
+
value: number;
|
|
8
|
+
timestampMs: number;
|
|
9
|
+
attributes: Attributes;
|
|
10
|
+
}
|
|
11
|
+
export interface LogRecord {
|
|
12
|
+
timestampMs: number;
|
|
13
|
+
severity: string;
|
|
14
|
+
body: string;
|
|
15
|
+
traceId: string | undefined;
|
|
16
|
+
spanId: string | undefined;
|
|
17
|
+
attributes: Attributes;
|
|
18
|
+
}
|
|
19
|
+
export interface MetricExporter {
|
|
20
|
+
export(metrics: MetricRecord[]): void;
|
|
21
|
+
}
|
|
22
|
+
export interface LogExporter {
|
|
23
|
+
export(logs: LogRecord[]): void;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/exporters/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE/D,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,CAAC;AAE3C,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,SAAS,GAAG,WAAW,GAAG,OAAO,CAAC;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,UAAU,CAAC;CACxB;AAED,MAAM,WAAW,SAAS;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,UAAU,EAAE,UAAU,CAAC;CACxB;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,OAAO,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC;CACvC;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,CAAC,IAAI,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;CACjC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export { otel } from './sdk';
|
|
2
|
+
export type { OtelConfig } from './sdk';
|
|
3
|
+
export { Span, NoopSpan } from './core/span';
|
|
4
|
+
export type { SpanKind, SpanStatus, SpanEvent, ReadonlySpan, } from './core/span';
|
|
5
|
+
export { Tracer } from './core/tracer';
|
|
6
|
+
export { Meter, Counter, Histogram, Gauge } from './core/meter';
|
|
7
|
+
export { OtelLogger } from './core/log-record';
|
|
8
|
+
export type { LogSeverity } from './core/log-record';
|
|
9
|
+
export type { Attributes, AttributeValue } from './core/attributes';
|
|
10
|
+
export type { Resource } from './core/resource';
|
|
11
|
+
export { spanContext } from './context/span-context';
|
|
12
|
+
export type { SpanExporter, MetricExporter, LogExporter, MetricRecord, LogRecord, } from './exporters/types';
|
|
13
|
+
export { ConsoleSpanExporter, ConsoleMetricExporter, ConsoleLogExporter, } from './exporters/console-exporter';
|
|
14
|
+
export { OtlpHttpExporter, OtlpHttpMetricExporter, OtlpHttpLogExporter, } from './exporters/otlp-http-exporter';
|
|
15
|
+
export type { OtlpHttpExporterOptions, OtlpHttpMetricExporterOptions, OtlpHttpLogExporterOptions, } from './exporters/otlp-http-exporter';
|
|
16
|
+
export { createNavigationInstrumentation } from './instrumentation/navigation';
|
|
17
|
+
export type { NavigationInstrumentation } from './instrumentation/navigation';
|
|
18
|
+
export { createAxiosInstrumentation } from './instrumentation/network';
|
|
19
|
+
export type { AxiosInstrumentation, AxiosInstrumentationOptions, AxiosRequestConfig as OtelAxiosRequestConfig, AxiosResponse as OtelAxiosResponse, } from './instrumentation/network';
|
|
20
|
+
export { installErrorInstrumentation } from './instrumentation/errors';
|
|
21
|
+
export type { StorageAdapter } from './instrumentation/errors';
|
|
22
|
+
export { OtelProvider, OtelContext } from './react/OtelProvider';
|
|
23
|
+
export type { OtelContextValue, OtelProviderProps } from './react/OtelProvider';
|
|
24
|
+
export { useOtel } from './react/useOtel';
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,OAAO,CAAC;AAC7B,YAAY,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAGxC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC7C,YAAY,EACV,QAAQ,EACR,UAAU,EACV,SAAS,EACT,YAAY,GACb,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,YAAY,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACpE,YAAY,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAGhD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAGrD,YAAY,EACV,YAAY,EACZ,cAAc,EACd,WAAW,EACX,YAAY,EACZ,SAAS,GACV,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,gBAAgB,EAChB,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,gCAAgC,CAAC;AACxC,YAAY,EACV,uBAAuB,EACvB,6BAA6B,EAC7B,0BAA0B,GAC3B,MAAM,gCAAgC,CAAC;AAGxC,OAAO,EAAE,+BAA+B,EAAE,MAAM,8BAA8B,CAAC;AAC/E,YAAY,EAAE,yBAAyB,EAAE,MAAM,8BAA8B,CAAC;AAC9E,OAAO,EAAE,0BAA0B,EAAE,MAAM,2BAA2B,CAAC;AACvE,YAAY,EACV,oBAAoB,EACpB,2BAA2B,EAC3B,kBAAkB,IAAI,sBAAsB,EAC5C,aAAa,IAAI,iBAAiB,GACnC,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AACvE,YAAY,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAG/D,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACjE,YAAY,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAChF,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Tracer } from '../core/tracer';
|
|
2
|
+
import type { ReadonlySpan } from '../exporters/types';
|
|
3
|
+
export interface StorageAdapter {
|
|
4
|
+
setSync(key: string, value: string): void;
|
|
5
|
+
getSync(key: string): string | null;
|
|
6
|
+
deleteSync(key: string): void;
|
|
7
|
+
}
|
|
8
|
+
export declare function installErrorInstrumentation(params: {
|
|
9
|
+
tracer: Tracer;
|
|
10
|
+
storage?: StorageAdapter;
|
|
11
|
+
exporter?: {
|
|
12
|
+
export(spans: ReadonlySpan[]): void;
|
|
13
|
+
};
|
|
14
|
+
}): void;
|
|
15
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../../src/instrumentation/errors.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAIvD,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1C,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IACpC,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B;AAqBD,wBAAgB,2BAA2B,CAAC,MAAM,EAAE;IAClD,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,QAAQ,CAAC,EAAE;QAAE,MAAM,CAAC,KAAK,EAAE,YAAY,EAAE,GAAG,IAAI,CAAA;KAAE,CAAC;CACpD,GAAG,IAAI,CAqDP"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../../../../src/instrumentation/lifecycle.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAUlE"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Tracer } from '../core/tracer';
|
|
2
|
+
export declare function createNavigationInstrumentation(tracer: Tracer): {
|
|
3
|
+
onRouteChange(currentName: string, previousName: string | undefined, currentKey: string, previousKey: string | undefined, params?: Record<string, unknown>): void;
|
|
4
|
+
endCurrentScreen(): void;
|
|
5
|
+
};
|
|
6
|
+
export type NavigationInstrumentation = ReturnType<typeof createNavigationInstrumentation>;
|
|
7
|
+
//# sourceMappingURL=navigation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigation.d.ts","sourceRoot":"","sources":["../../../../src/instrumentation/navigation.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAKxC,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,MAAM;+BAG3C,MAAM,gBACL,MAAM,GAAG,SAAS,cACpB,MAAM,eACL,MAAM,GAAG,SAAS,WACtB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B,IAAI;wBAwBa,IAAI;EAe3B;AAED,MAAM,MAAM,yBAAyB,GAAG,UAAU,CAChD,OAAO,+BAA+B,CACvC,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Tracer } from '../core/tracer';
|
|
2
|
+
export interface AxiosRequestConfig {
|
|
3
|
+
method?: string;
|
|
4
|
+
url?: string;
|
|
5
|
+
headers?: Record<string, unknown>;
|
|
6
|
+
params?: Record<string, unknown>;
|
|
7
|
+
data?: unknown;
|
|
8
|
+
__otelId?: string;
|
|
9
|
+
[key: string]: unknown;
|
|
10
|
+
}
|
|
11
|
+
export interface AxiosResponse {
|
|
12
|
+
status: number;
|
|
13
|
+
headers?: Record<string, unknown>;
|
|
14
|
+
data?: unknown;
|
|
15
|
+
config: AxiosRequestConfig;
|
|
16
|
+
[key: string]: unknown;
|
|
17
|
+
}
|
|
18
|
+
export interface AxiosError {
|
|
19
|
+
message: string;
|
|
20
|
+
response?: AxiosResponse;
|
|
21
|
+
config?: AxiosRequestConfig;
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
}
|
|
24
|
+
export interface AxiosInstrumentationOptions {
|
|
25
|
+
sensitiveKeys?: string[];
|
|
26
|
+
}
|
|
27
|
+
export declare function createAxiosInstrumentation(tracer: Tracer, options?: AxiosInstrumentationOptions): {
|
|
28
|
+
onRequest(config: AxiosRequestConfig): AxiosRequestConfig;
|
|
29
|
+
onResponse(response: AxiosResponse): AxiosResponse;
|
|
30
|
+
onError(error: AxiosError): Promise<never>;
|
|
31
|
+
};
|
|
32
|
+
export type AxiosInstrumentation = ReturnType<typeof createAxiosInstrumentation>;
|
|
33
|
+
//# sourceMappingURL=network.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../../../../src/instrumentation/network.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAOxC,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,kBAAkB,CAAC;IAC3B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,MAAM,CAAC,EAAE,kBAAkB,CAAC;IAC5B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAqED,MAAM,WAAW,2BAA2B;IAM1C,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE,2BAA2B;sBAWjB,kBAAkB,GAAG,kBAAkB;yBAmDpC,aAAa,GAAG,aAAa;mBA+BnC,UAAU,GAAG,OAAO,CAAC,KAAK,CAAC;EAqC7C;AAED,MAAM,MAAM,oBAAoB,GAAG,UAAU,CAC3C,OAAO,0BAA0B,CAClC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React, { type ReactNode } from 'react';
|
|
2
|
+
import { OtelLogger } from '../core/log-record';
|
|
3
|
+
import { Meter } from '../core/meter';
|
|
4
|
+
import { Tracer } from '../core/tracer';
|
|
5
|
+
export interface OtelContextValue {
|
|
6
|
+
tracer: Tracer;
|
|
7
|
+
meter: Meter;
|
|
8
|
+
logger: OtelLogger;
|
|
9
|
+
recordEvent: (name: string, attributes?: Record<string, unknown>) => void;
|
|
10
|
+
setUser: (user: {
|
|
11
|
+
id?: string;
|
|
12
|
+
email?: string;
|
|
13
|
+
}) => void;
|
|
14
|
+
}
|
|
15
|
+
export declare const OtelContext: React.Context<OtelContextValue | undefined>;
|
|
16
|
+
export interface OtelProviderProps {
|
|
17
|
+
children: ReactNode;
|
|
18
|
+
withErrorBoundary?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export declare function OtelProvider({ children, withErrorBoundary, }: OtelProviderProps): React.ReactElement;
|
|
21
|
+
//# sourceMappingURL=OtelProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OtelProvider.d.ts","sourceRoot":"","sources":["../../../../src/react/OtelProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAIZ,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGxC,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,KAAK,CAAC;IACb,MAAM,EAAE,UAAU,CAAC;IACnB,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;IAC1E,OAAO,EAAE,CAAC,IAAI,EAAE;QAAE,EAAE,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;CAC1D;AAED,eAAO,MAAM,WAAW,6CAEvB,CAAC;AAsCF,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,SAAS,CAAC;IACpB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED,wBAAgB,YAAY,CAAC,EAC3B,QAAQ,EACR,iBAAyB,GAC1B,EAAE,iBAAiB,GAAG,KAAK,CAAC,YAAY,CA6BxC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOtel.d.ts","sourceRoot":"","sources":["../../../../src/react/useOtel.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGvD,wBAAgB,OAAO,IAAI,gBAAgB,CAQ1C"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { SpanExporter, MetricExporter, LogExporter } from './exporters/types';
|
|
2
|
+
import type { StorageAdapter } from './instrumentation/errors';
|
|
3
|
+
import { OtelLogger } from './core/log-record';
|
|
4
|
+
import { Meter } from './core/meter';
|
|
5
|
+
import { Tracer } from './core/tracer';
|
|
6
|
+
export interface OtelConfig {
|
|
7
|
+
serviceName: string;
|
|
8
|
+
serviceVersion?: string;
|
|
9
|
+
osName?: string;
|
|
10
|
+
osVersion?: string;
|
|
11
|
+
deviceBrand?: string;
|
|
12
|
+
deviceModel?: string;
|
|
13
|
+
deviceType?: string | number;
|
|
14
|
+
appBuild?: string;
|
|
15
|
+
environment?: string;
|
|
16
|
+
exporter?: SpanExporter;
|
|
17
|
+
metricExporter?: MetricExporter;
|
|
18
|
+
logExporter?: LogExporter;
|
|
19
|
+
sampleRate?: number;
|
|
20
|
+
debug?: boolean;
|
|
21
|
+
storage?: StorageAdapter;
|
|
22
|
+
maxAttributeStringLength?: number;
|
|
23
|
+
sensitiveKeys?: string[];
|
|
24
|
+
}
|
|
25
|
+
declare class OtelSDK {
|
|
26
|
+
private userAttributes_;
|
|
27
|
+
private tracer_;
|
|
28
|
+
private meter_;
|
|
29
|
+
private logger_;
|
|
30
|
+
private resource_;
|
|
31
|
+
private exporter_;
|
|
32
|
+
private metricExporter_;
|
|
33
|
+
private logExporter_;
|
|
34
|
+
private sensitiveKeys_;
|
|
35
|
+
private initialized;
|
|
36
|
+
init(config: OtelConfig): void;
|
|
37
|
+
recordEvent(name: string, properties?: Record<string, unknown>): void;
|
|
38
|
+
setUser(user: {
|
|
39
|
+
id?: string;
|
|
40
|
+
email?: string;
|
|
41
|
+
}): void;
|
|
42
|
+
getTracer(): Tracer;
|
|
43
|
+
getMeter(): Meter;
|
|
44
|
+
getSensitiveKeys(): string[];
|
|
45
|
+
getLogger(): OtelLogger;
|
|
46
|
+
shutdown(): Promise<void>;
|
|
47
|
+
}
|
|
48
|
+
export declare const otel: OtelSDK;
|
|
49
|
+
export {};
|
|
50
|
+
//# sourceMappingURL=sdk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sdk.d.ts","sourceRoot":"","sources":["../../../src/sdk.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,YAAY,EACZ,cAAc,EACd,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAG/D,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAErC,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAIvC,MAAM,WAAW,UAAU;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,cAAc,CAAC;IAEzB,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAIlC,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;CAC1B;AAED,cAAM,OAAO;IACX,OAAO,CAAC,eAAe,CAAkB;IACzC,OAAO,CAAC,OAAO,CAAqB;IACpC,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,OAAO,CAAyB;IACxC,OAAO,CAAC,SAAS,CAAiC;IAClD,OAAO,CAAC,SAAS,CAA2B;IAC5C,OAAO,CAAC,eAAe,CAA6B;IACpD,OAAO,CAAC,YAAY,CAA0B;IAC9C,OAAO,CAAC,cAAc,CAAgB;IACtC,OAAO,CAAC,WAAW,CAAS;IAE5B,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;IA4D9B,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAIrE,OAAO,CAAC,IAAI,EAAE;QAAE,EAAE,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI;IAOpD,SAAS,IAAI,MAAM;IASnB,QAAQ,IAAI,KAAK;IASjB,gBAAgB,IAAI,MAAM,EAAE;IAI5B,SAAS,IAAI,UAAU;IASjB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAqBhC;AAED,eAAO,MAAM,IAAI,SAAgB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-native-otel",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Lightweight OpenTelemetry SDK for React Native",
|
|
5
|
+
"main": "./lib/module/index.js",
|
|
6
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"source": "./src/index.ts",
|
|
10
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
11
|
+
"default": "./lib/module/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"src",
|
|
17
|
+
"lib",
|
|
18
|
+
"android",
|
|
19
|
+
"ios",
|
|
20
|
+
"cpp",
|
|
21
|
+
"*.podspec",
|
|
22
|
+
"react-native.config.js",
|
|
23
|
+
"!ios/build",
|
|
24
|
+
"!android/build",
|
|
25
|
+
"!android/gradle",
|
|
26
|
+
"!android/gradlew",
|
|
27
|
+
"!android/gradlew.bat",
|
|
28
|
+
"!android/local.properties",
|
|
29
|
+
"!**/__tests__",
|
|
30
|
+
"!**/__fixtures__",
|
|
31
|
+
"!**/__mocks__",
|
|
32
|
+
"!**/.*"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"example": "yarn workspace react-native-otel-example",
|
|
36
|
+
"clean": "del-cli lib",
|
|
37
|
+
"prepare": "bob build",
|
|
38
|
+
"typecheck": "tsc",
|
|
39
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\""
|
|
40
|
+
},
|
|
41
|
+
"keywords": [
|
|
42
|
+
"react-native",
|
|
43
|
+
"ios",
|
|
44
|
+
"android",
|
|
45
|
+
"opentelemetry",
|
|
46
|
+
"otel",
|
|
47
|
+
"observability",
|
|
48
|
+
"tracing"
|
|
49
|
+
],
|
|
50
|
+
"repository": {
|
|
51
|
+
"type": "git",
|
|
52
|
+
"url": "git+https://github.com/03balogun/react-native-otel.git"
|
|
53
|
+
},
|
|
54
|
+
"author": "Wahab Balogun (https://github.com/03balogun)",
|
|
55
|
+
"license": "MIT",
|
|
56
|
+
"bugs": {
|
|
57
|
+
"url": "https://github.com/03balogun/react-native-otel/issues"
|
|
58
|
+
},
|
|
59
|
+
"homepage": "https://github.com/03balogun/react-native-otel#readme",
|
|
60
|
+
"publishConfig": {
|
|
61
|
+
"registry": "https://registry.npmjs.org/"
|
|
62
|
+
},
|
|
63
|
+
"devDependencies": {
|
|
64
|
+
"@eslint/compat": "^1.3.2",
|
|
65
|
+
"@eslint/eslintrc": "^3.3.1",
|
|
66
|
+
"@eslint/js": "^9.35.0",
|
|
67
|
+
"@react-native/babel-preset": "0.83.0",
|
|
68
|
+
"@react-native/eslint-config": "0.83.0",
|
|
69
|
+
"@types/react": "^19.1.12",
|
|
70
|
+
"del-cli": "^6.0.0",
|
|
71
|
+
"eslint": "^9.35.0",
|
|
72
|
+
"eslint-config-prettier": "^10.1.8",
|
|
73
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
74
|
+
"prettier": "^2.8.8",
|
|
75
|
+
"react": "19.2.0",
|
|
76
|
+
"react-native": "0.83.2",
|
|
77
|
+
"react-native-builder-bob": "^0.40.13",
|
|
78
|
+
"turbo": "^2.5.6",
|
|
79
|
+
"typescript": "^5.9.2"
|
|
80
|
+
},
|
|
81
|
+
"dependencies": {
|
|
82
|
+
"@opentelemetry/semantic-conventions": "^1.39.0"
|
|
83
|
+
},
|
|
84
|
+
"peerDependencies": {
|
|
85
|
+
"react": "*",
|
|
86
|
+
"react-native": "*"
|
|
87
|
+
},
|
|
88
|
+
"workspaces": [
|
|
89
|
+
"example"
|
|
90
|
+
],
|
|
91
|
+
"packageManager": "yarn@4.11.0",
|
|
92
|
+
"react-native-builder-bob": {
|
|
93
|
+
"source": "src",
|
|
94
|
+
"output": "lib",
|
|
95
|
+
"targets": [
|
|
96
|
+
[
|
|
97
|
+
"module",
|
|
98
|
+
{
|
|
99
|
+
"esm": true
|
|
100
|
+
}
|
|
101
|
+
],
|
|
102
|
+
[
|
|
103
|
+
"typescript",
|
|
104
|
+
{
|
|
105
|
+
"project": "tsconfig.build.json"
|
|
106
|
+
}
|
|
107
|
+
]
|
|
108
|
+
]
|
|
109
|
+
},
|
|
110
|
+
"prettier": {
|
|
111
|
+
"quoteProps": "consistent",
|
|
112
|
+
"singleQuote": true,
|
|
113
|
+
"tabWidth": 2,
|
|
114
|
+
"trailingComma": "es5",
|
|
115
|
+
"useTabs": false
|
|
116
|
+
},
|
|
117
|
+
"create-react-native-library": {
|
|
118
|
+
"type": "library",
|
|
119
|
+
"languages": "js",
|
|
120
|
+
"tools": [
|
|
121
|
+
"eslint"
|
|
122
|
+
],
|
|
123
|
+
"version": "0.57.2"
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Span, NoopSpan } from '../core/span';
|
|
2
|
+
|
|
3
|
+
// Module-level singleton. Tracks only the current active screen span.
|
|
4
|
+
// Network spans do NOT touch this context (handled via activeNetworkSpans map).
|
|
5
|
+
class SpanContextManager {
|
|
6
|
+
private current_: Span | NoopSpan | undefined;
|
|
7
|
+
|
|
8
|
+
setCurrent(span: Span | NoopSpan | undefined): void {
|
|
9
|
+
this.current_ = span;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
current(): Span | NoopSpan | undefined {
|
|
13
|
+
return this.current_;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const spanContext = new SpanContextManager();
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
let maxStringLength = 1024;
|
|
2
|
+
|
|
3
|
+
export function setMaxStringLength(length: number): void {
|
|
4
|
+
maxStringLength = length;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export type AttributeValue =
|
|
8
|
+
| string
|
|
9
|
+
| number
|
|
10
|
+
| boolean
|
|
11
|
+
| string[]
|
|
12
|
+
| number[]
|
|
13
|
+
| boolean[];
|
|
14
|
+
export type Attributes = Record<string, AttributeValue>;
|
|
15
|
+
|
|
16
|
+
// Sanitize a single value. Returns undefined for null/undefined inputs so the
|
|
17
|
+
// caller can skip writing the key entirely — no object allocation needed.
|
|
18
|
+
// Accepts `unknown` so loose props (e.g. from analytics trackEvent) are safe.
|
|
19
|
+
export function sanitizeValue(value: unknown): AttributeValue | undefined {
|
|
20
|
+
if (value === undefined || value === null) return undefined;
|
|
21
|
+
if (typeof value === 'string') {
|
|
22
|
+
return value.length > maxStringLength
|
|
23
|
+
? value.slice(0, maxStringLength)
|
|
24
|
+
: value;
|
|
25
|
+
}
|
|
26
|
+
if (typeof value === 'number' || typeof value === 'boolean') return value;
|
|
27
|
+
if (Array.isArray(value)) {
|
|
28
|
+
return (value as unknown[]).map((v) =>
|
|
29
|
+
typeof v === 'string' && v.length > maxStringLength
|
|
30
|
+
? v.slice(0, maxStringLength)
|
|
31
|
+
: v
|
|
32
|
+
) as AttributeValue;
|
|
33
|
+
}
|
|
34
|
+
// Plain objects → JSON string so they don't become '[object Object]'
|
|
35
|
+
if (typeof value === 'object') {
|
|
36
|
+
try {
|
|
37
|
+
const json = JSON.stringify(value);
|
|
38
|
+
return json.length > maxStringLength
|
|
39
|
+
? json.slice(0, maxStringLength)
|
|
40
|
+
: json;
|
|
41
|
+
} catch {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// Bulk sanitize used once in the Span constructor and addEvent.
|
|
49
|
+
// Accepts Record<string, unknown> so callers don't need to pre-cast.
|
|
50
|
+
export function sanitizeAttributes(
|
|
51
|
+
attrs: Attributes | Record<string, unknown>
|
|
52
|
+
): Attributes {
|
|
53
|
+
const result: Attributes = {};
|
|
54
|
+
for (const key of Object.keys(attrs)) {
|
|
55
|
+
const sanitized = sanitizeValue(attrs[key]);
|
|
56
|
+
if (sanitized !== undefined) {
|
|
57
|
+
result[key] = sanitized;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
}
|
package/src/core/ids.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
function randomHex(length: number): string {
|
|
2
|
+
let result = '';
|
|
3
|
+
for (let i = 0; i < length; i++) {
|
|
4
|
+
result += Math.floor(Math.random() * 16).toString(16);
|
|
5
|
+
}
|
|
6
|
+
return result;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function generateTraceId(): string {
|
|
10
|
+
return randomHex(32);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function generateSpanId(): string {
|
|
14
|
+
return randomHex(16);
|
|
15
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { Attributes } from './attributes';
|
|
2
|
+
import type { LogExporter, LogRecord } from '../exporters/types';
|
|
3
|
+
import { sanitizeAttributes } from './attributes';
|
|
4
|
+
import { now } from './clock';
|
|
5
|
+
import { spanContext } from '../context/span-context';
|
|
6
|
+
|
|
7
|
+
export type LogSeverity =
|
|
8
|
+
| 'TRACE'
|
|
9
|
+
| 'DEBUG'
|
|
10
|
+
| 'INFO'
|
|
11
|
+
| 'WARN'
|
|
12
|
+
| 'ERROR'
|
|
13
|
+
| 'FATAL';
|
|
14
|
+
|
|
15
|
+
export class OtelLogger {
|
|
16
|
+
private exporter: LogExporter | undefined;
|
|
17
|
+
|
|
18
|
+
constructor(exporter?: LogExporter) {
|
|
19
|
+
this.exporter = exporter;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
private emit(severity: LogSeverity, body: string, attrs?: Attributes): void {
|
|
23
|
+
const current = spanContext.current();
|
|
24
|
+
const record: LogRecord = {
|
|
25
|
+
timestampMs: now(),
|
|
26
|
+
severity,
|
|
27
|
+
body,
|
|
28
|
+
traceId: current?.traceId,
|
|
29
|
+
spanId: current?.spanId,
|
|
30
|
+
attributes: attrs ? sanitizeAttributes(attrs) : {},
|
|
31
|
+
};
|
|
32
|
+
this.exporter?.export([record]);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
trace(body: string, attrs?: Attributes): void {
|
|
36
|
+
this.emit('TRACE', body, attrs);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
debug(body: string, attrs?: Attributes): void {
|
|
40
|
+
this.emit('DEBUG', body, attrs);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
info(body: string, attrs?: Attributes): void {
|
|
44
|
+
this.emit('INFO', body, attrs);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
warn(body: string, attrs?: Attributes): void {
|
|
48
|
+
this.emit('WARN', body, attrs);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
error(body: string, attrs?: Attributes): void {
|
|
52
|
+
this.emit('ERROR', body, attrs);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
fatal(body: string, attrs?: Attributes): void {
|
|
56
|
+
this.emit('FATAL', body, attrs);
|
|
57
|
+
}
|
|
58
|
+
}
|