@ogcio/o11y-sdk-react 0.1.0-beta.2 → 0.1.0-beta.4
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/CHANGELOG.md +14 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/lib/index.d.ts +39 -0
- package/dist/lib/index.js +1 -0
- package/dist/lib/instrumentation.faro.d.ts +3 -0
- package/dist/lib/instrumentation.faro.js +69 -0
- package/dist/vitest.config.d.ts +2 -0
- package/dist/vitest.config.js +25 -0
- package/lib/instrumentation.faro.ts +9 -1
- package/package.json +9 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.1.0-beta.4](https://github.com/ogcio/o11y/compare/@ogcio/o11y-sdk-react@v0.1.0-beta.3...@ogcio/o11y-sdk-react@v0.1.0-beta.4) (2025-02-18)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* remove pnpm test on prepublishOnly script ([#68](https://github.com/ogcio/o11y/issues/68)) ([41f6f57](https://github.com/ogcio/o11y/commit/41f6f57fa415c4f7adc29f49f983539274ef7320))
|
|
9
|
+
|
|
10
|
+
## [0.1.0-beta.3](https://github.com/ogcio/o11y/compare/@ogcio/o11y-sdk-react@v0.1.0-beta.2...@ogcio/o11y-sdk-react@v0.1.0-beta.3) (2025-01-28)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* prepublishOnly hook ([#60](https://github.com/ogcio/o11y/issues/60)) ([9fbd3ad](https://github.com/ogcio/o11y/commit/9fbd3ad0b45a1604cf2eccc26b2f8855640417a1))
|
|
16
|
+
|
|
3
17
|
## [0.1.0-beta.2](https://github.com/ogcio/o11y/compare/@ogcio/o11y-sdk-react@v0.1.0-beta.1...@ogcio/o11y-sdk-react@v0.1.0-beta.2) (2025-01-28)
|
|
4
18
|
|
|
5
19
|
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Faro, withFaroErrorBoundary, withFaroProfiler } from "@grafana/faro-react";
|
|
2
|
+
import buildFaroInstrumentation from "./lib/instrumentation.faro.js";
|
|
3
|
+
export * from "./lib/index.js";
|
|
4
|
+
export { withFaroErrorBoundary, withFaroProfiler, Faro };
|
|
5
|
+
export { buildFaroInstrumentation as instrumentFaro };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { withFaroErrorBoundary, withFaroProfiler, } from "@grafana/faro-react";
|
|
2
|
+
import buildFaroInstrumentation from "./lib/instrumentation.faro.js";
|
|
3
|
+
export * from "./lib/index.js";
|
|
4
|
+
export { withFaroErrorBoundary, withFaroProfiler };
|
|
5
|
+
export { buildFaroInstrumentation as instrumentFaro };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
interface SDKConfig {
|
|
2
|
+
/**
|
|
3
|
+
* The opentelemetry collector entrypoint GRPC url.
|
|
4
|
+
* If the collectoUrl is null or undefined, the instrumentation will not be activated.
|
|
5
|
+
* @example http://alloy:4317
|
|
6
|
+
*/
|
|
7
|
+
collectorUrl: string;
|
|
8
|
+
/**
|
|
9
|
+
* Name of your application used for the collector to group logs
|
|
10
|
+
*/
|
|
11
|
+
serviceName?: string;
|
|
12
|
+
/**
|
|
13
|
+
* Diagnostic log level for the internal runtime instrumentation
|
|
14
|
+
*
|
|
15
|
+
* @type string
|
|
16
|
+
* @default INFO
|
|
17
|
+
*/
|
|
18
|
+
diagLogLevel?: SDKLogLevel;
|
|
19
|
+
/**
|
|
20
|
+
* Collector signals processing mode.
|
|
21
|
+
* signle: makes an http/grpc request for each signal and it is immediately processed inside grafana
|
|
22
|
+
* batch: sends multiple signals within a time window, optimized to reduce http/grpc calls in production
|
|
23
|
+
*
|
|
24
|
+
* @type string
|
|
25
|
+
* @default batch
|
|
26
|
+
*/
|
|
27
|
+
collectorMode?: SDKCollectorMode;
|
|
28
|
+
}
|
|
29
|
+
export interface FaroSDKConfig extends SDKConfig {
|
|
30
|
+
/**
|
|
31
|
+
* String with single or multiple URLs separated by comma used by the instrumentation to ignore CORS errors and send signals through it
|
|
32
|
+
* @example http://localhost:9000,http://localhost:8000
|
|
33
|
+
* @example http://localhost:9000
|
|
34
|
+
*/
|
|
35
|
+
corsTraceHeaders?: string;
|
|
36
|
+
}
|
|
37
|
+
export type SDKCollectorMode = "single" | "batch";
|
|
38
|
+
export type SDKLogLevel = "NONE" | "ERROR" | "WARN" | "INFO" | "DEBUG" | "VERBOSE" | "ALL";
|
|
39
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { ErrorsInstrumentation, getWebInstrumentations, initializeFaro, WebVitalsInstrumentation, } from "@grafana/faro-react";
|
|
2
|
+
import { diag, DiagConsoleLogger, DiagLogLevel } from "@opentelemetry/api";
|
|
3
|
+
import { W3CTraceContextPropagator } from "@opentelemetry/core";
|
|
4
|
+
import { FetchInstrumentation } from "@opentelemetry/instrumentation-fetch";
|
|
5
|
+
import { UserInteractionInstrumentation } from "@opentelemetry/instrumentation-user-interaction";
|
|
6
|
+
import { DocumentLoadInstrumentation } from "@opentelemetry/instrumentation-document-load";
|
|
7
|
+
import { TracingInstrumentation } from "@grafana/faro-web-tracing";
|
|
8
|
+
export default function buildFaroInstrumentation(config) {
|
|
9
|
+
if (!config) {
|
|
10
|
+
console.warn("observability config not set. Skipping Faro OpenTelemetry instrumentation.");
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (!config.collectorUrl) {
|
|
14
|
+
console.warn("collectorUrl not set. Skipping Faro OpenTelemetry instrumentation.");
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (!isUrl(config.collectorUrl)) {
|
|
18
|
+
console.error("collectorUrl does not use a valid format. Skipping Faro OpenTelemetry instrumentation.");
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
try {
|
|
22
|
+
diag.setLogger(new DiagConsoleLogger(), config.diagLogLevel
|
|
23
|
+
? DiagLogLevel[config.diagLogLevel]
|
|
24
|
+
: DiagLogLevel.INFO);
|
|
25
|
+
const faro = initializeFaro({
|
|
26
|
+
url: config.collectorUrl,
|
|
27
|
+
app: {
|
|
28
|
+
name: config.serviceName,
|
|
29
|
+
},
|
|
30
|
+
batching: {
|
|
31
|
+
enabled: !(config.collectorMode === "single"),
|
|
32
|
+
},
|
|
33
|
+
instrumentations: [
|
|
34
|
+
...getWebInstrumentations({
|
|
35
|
+
captureConsole: true,
|
|
36
|
+
}),
|
|
37
|
+
new ErrorsInstrumentation(),
|
|
38
|
+
new WebVitalsInstrumentation(),
|
|
39
|
+
new TracingInstrumentation({
|
|
40
|
+
propagator: new W3CTraceContextPropagator(),
|
|
41
|
+
instrumentations: [
|
|
42
|
+
new DocumentLoadInstrumentation(),
|
|
43
|
+
new FetchInstrumentation({
|
|
44
|
+
ignoreUrls: [config.collectorUrl], // ignore collector to avoid fetch loop
|
|
45
|
+
propagateTraceHeaderCorsUrls: config.corsTraceHeaders
|
|
46
|
+
? config.corsTraceHeaders.split(",").map((s) => new RegExp(s))
|
|
47
|
+
: undefined,
|
|
48
|
+
}),
|
|
49
|
+
new UserInteractionInstrumentation(),
|
|
50
|
+
],
|
|
51
|
+
}),
|
|
52
|
+
],
|
|
53
|
+
});
|
|
54
|
+
console.log("Faro OpenTelemetry instrumentation started successfully.");
|
|
55
|
+
return faro;
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
console.error("Error starting Faro OpenTelemetry instrumentation:", error);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function isUrl(url) {
|
|
62
|
+
try {
|
|
63
|
+
new URL(url);
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
catch (_) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { defineConfig } from "vitest/config";
|
|
2
|
+
export default defineConfig({
|
|
3
|
+
test: {
|
|
4
|
+
globals: true,
|
|
5
|
+
watch: false,
|
|
6
|
+
include: ["**/test/*.test.ts"],
|
|
7
|
+
exclude: ["**/fixtures/**", "**/dist/**"],
|
|
8
|
+
poolOptions: {
|
|
9
|
+
threads: {
|
|
10
|
+
maxThreads: 8,
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
clearMocks: true,
|
|
14
|
+
testTimeout: 30_000,
|
|
15
|
+
coverage: {
|
|
16
|
+
enabled: true,
|
|
17
|
+
provider: "v8",
|
|
18
|
+
reportsDirectory: "coverage",
|
|
19
|
+
reporter: ["lcov", "cobertura"],
|
|
20
|
+
clean: true,
|
|
21
|
+
},
|
|
22
|
+
reporters: ["default", ["junit", { outputFile: "test-report.xml" }]],
|
|
23
|
+
environment: "node",
|
|
24
|
+
},
|
|
25
|
+
});
|
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
} from "@grafana/faro-react";
|
|
9
9
|
import { diag, DiagConsoleLogger, DiagLogLevel } from "@opentelemetry/api";
|
|
10
10
|
import { W3CTraceContextPropagator } from "@opentelemetry/core";
|
|
11
|
-
import isUrl from "is-url";
|
|
12
11
|
import { FetchInstrumentation } from "@opentelemetry/instrumentation-fetch";
|
|
13
12
|
import { UserInteractionInstrumentation } from "@opentelemetry/instrumentation-user-interaction";
|
|
14
13
|
import { DocumentLoadInstrumentation } from "@opentelemetry/instrumentation-document-load";
|
|
@@ -82,3 +81,12 @@ export default function buildFaroInstrumentation(
|
|
|
82
81
|
console.error("Error starting Faro OpenTelemetry instrumentation:", error);
|
|
83
82
|
}
|
|
84
83
|
}
|
|
84
|
+
|
|
85
|
+
function isUrl(url: string): boolean {
|
|
86
|
+
try {
|
|
87
|
+
new URL(url);
|
|
88
|
+
return true;
|
|
89
|
+
} catch (_) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ogcio/o11y-sdk-react",
|
|
3
|
-
"version": "0.1.0-beta.
|
|
3
|
+
"version": "0.1.0-beta.4",
|
|
4
4
|
"description": "Opentelemetry standard instrumentation SDK for React based project",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -19,23 +19,21 @@
|
|
|
19
19
|
"author": "team:ogcio/observability",
|
|
20
20
|
"license": "ISC",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@grafana/faro-react": "^1.
|
|
23
|
-
"@grafana/faro-web-sdk": "^1.
|
|
24
|
-
"@grafana/faro-web-tracing": "^1.
|
|
22
|
+
"@grafana/faro-react": "^1.13.3",
|
|
23
|
+
"@grafana/faro-web-sdk": "^1.13.3",
|
|
24
|
+
"@grafana/faro-web-tracing": "^1.13.3",
|
|
25
25
|
"@opentelemetry/api": "^1.9.0",
|
|
26
26
|
"@opentelemetry/core": "1.30.1",
|
|
27
27
|
"@opentelemetry/instrumentation-document-load": "^0.44.0",
|
|
28
|
-
"@opentelemetry/instrumentation-fetch": "^0.57.
|
|
29
|
-
"@opentelemetry/instrumentation-user-interaction": "^0.44.0"
|
|
30
|
-
"is-url": "^1.2.4"
|
|
28
|
+
"@opentelemetry/instrumentation-fetch": "^0.57.2",
|
|
29
|
+
"@opentelemetry/instrumentation-user-interaction": "^0.44.0"
|
|
31
30
|
},
|
|
32
31
|
"devDependencies": {
|
|
33
|
-
"@types/
|
|
34
|
-
"@
|
|
35
|
-
"@vitest/coverage-v8": "^3.0.4",
|
|
32
|
+
"@types/node": "^22.13.4",
|
|
33
|
+
"@vitest/coverage-v8": "^3.0.5",
|
|
36
34
|
"tsx": "^4.19.2",
|
|
37
35
|
"typescript": "^5.7.3",
|
|
38
|
-
"vitest": "^3.0.
|
|
36
|
+
"vitest": "^3.0.5"
|
|
39
37
|
},
|
|
40
38
|
"scripts": {
|
|
41
39
|
"build": "rm -rf dist && tsc -p tsconfig.json",
|