@ogcio/o11y-sdk-node 0.4.0 → 0.4.2

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 (33) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/lib/config-manager.d.ts +1 -1
  3. package/dist/lib/config-manager.js +1 -4
  4. package/dist/lib/exporter/pii-exporter-decorator.d.ts +1 -1
  5. package/dist/lib/exporter/pii-exporter-decorator.js +10 -10
  6. package/dist/lib/internals/redaction/pii-detection.d.ts +11 -9
  7. package/dist/lib/internals/redaction/pii-detection.js +17 -24
  8. package/dist/lib/internals/redaction/redactors/ip.js +2 -2
  9. package/dist/lib/traces.js +1 -1
  10. package/dist/package.json +1 -1
  11. package/dist/vitest.config.js +1 -1
  12. package/lib/config-manager.ts +2 -6
  13. package/lib/exporter/pii-exporter-decorator.ts +15 -12
  14. package/lib/internals/redaction/pii-detection.ts +27 -40
  15. package/lib/internals/redaction/redactors/ip.ts +2 -2
  16. package/lib/traces.ts +2 -2
  17. package/package.json +1 -1
  18. package/test/config-manager.test.ts +2 -2
  19. package/test/integration/README.md +59 -11
  20. package/test/integration/docker-utils.sh +214 -0
  21. package/test/integration/main.sh +52 -0
  22. package/test/integration/teardown.sh +7 -0
  23. package/test/integration/{http-tracing.integration.test.ts → test_fastify-o11y-pii-enabled/http-tracing.integration.test.ts} +1 -1
  24. package/test/integration/{pii.integration.test.ts → test_fastify-o11y-pii-enabled/pii.integration.test.ts} +1 -1
  25. package/test/integration/test_fastify-o11y-pii-enabled/run.sh +42 -0
  26. package/test/integration/test_without-o11y/run.sh +30 -0
  27. package/test/integration/test_without-o11y/verify-status.integration.test.ts +32 -0
  28. package/test/internals/pii-detection.test.ts +142 -20
  29. package/test/internals/redactors/ip.test.ts +4 -0
  30. package/test/traces/active-span.test.ts +2 -4
  31. package/test/traces/with-span.test.ts +16 -0
  32. package/vitest.config.ts +1 -1
  33. package/test/integration/run.sh +0 -88
@@ -10,6 +10,22 @@ import { afterAll, afterEach, beforeAll, describe, expect, it } from "vitest";
10
10
  import { setNodeSdkConfig } from "../../lib/config-manager.js";
11
11
  import { getActiveSpan, withSpan } from "../../lib/traces.js";
12
12
 
13
+ describe("withSpan with opentelemetry not initialized", () => {
14
+ it("should handle noop span", async ({}) => {
15
+ let capturedSpan: Span;
16
+
17
+ await withSpan({
18
+ spanName: "test-sync-span",
19
+ fn: (span: Span) => {
20
+ capturedSpan = span;
21
+ },
22
+ });
23
+
24
+ expect(capturedSpan).not.toBeNull();
25
+ expect(capturedSpan.constructor.name).toBe("NonRecordingSpan");
26
+ });
27
+ });
28
+
13
29
  describe("withSpan", () => {
14
30
  let memoryExporter: InMemorySpanExporter;
15
31
  let spanProcessor: SpanProcessor;
package/vitest.config.ts CHANGED
@@ -37,7 +37,7 @@ export default defineConfig({
37
37
  },
38
38
  {
39
39
  test: {
40
- include: ["**/test/integration/*.test.ts"],
40
+ include: ["**/test/integration/**/*.test.ts"],
41
41
  name: "integration",
42
42
  },
43
43
  },
@@ -1,88 +0,0 @@
1
- BUILD_ID=$1
2
- ROOT_PATH=$2
3
-
4
- NETWORK_NAME="${BUILD_ID}_testnetwork"
5
- ALLOY_CONTAINER_NAME="integrationalloy"
6
- NODE_CONTAINER_NAME="${BUILD_ID}_fastify_app"
7
- ERROR_CODE=0
8
-
9
- docker build -t ${NODE_CONTAINER_NAME}:${BUILD_ID} -f $ROOT_PATH/examples/fastify/Dockerfile $ROOT_PATH/
10
-
11
- docker network create $NETWORK_NAME
12
-
13
- docker run -d \
14
- -v "$ROOT_PATH/alloy/integration-test.alloy:/etc/alloy/config.alloy:ro" \
15
- --network $NETWORK_NAME \
16
- --name $ALLOY_CONTAINER_NAME \
17
- -p 4317:4317 \
18
- -p 4318:4318 \
19
- grafana/alloy:v1.9.2 \
20
- run --server.http.listen-addr=0.0.0.0:12345 --stability.level=experimental /etc/alloy/config.alloy
21
-
22
- MAX_RETRIES=10
23
- COUNTER=0
24
- echo "$ALLOY_CONTAINER_NAME container status"
25
- until [ "$(docker inspect -f {{.State.Running}} $ALLOY_CONTAINER_NAME)" = true ]; do
26
- sleep 2
27
- docker inspect -f {{.State.Running}} $ALLOY_CONTAINER_NAME
28
- COUNTER=$((COUNTER + 1))
29
- if [ $COUNTER -ge $MAX_RETRIES ]; then
30
- echo "Exceeded maximum retries. Exiting."
31
- ERROR_CODE=1
32
- break
33
- fi
34
- done
35
-
36
- if [[ $ERROR_CODE -eq 0 ]]; then
37
- docker run --detach \
38
- --network $NETWORK_NAME \
39
- --name $NODE_CONTAINER_NAME \
40
- -e DB_DISABLED="true" \
41
- -e SERVER_HOST="0.0.0.0" \
42
- -e OTEL_COLLECTOR_URL="http://integrationalloy:4317" \
43
- --health-cmd="curl -f http://${NODE_CONTAINER_NAME}:9091/api/health > /dev/null || exit 1" \
44
- --health-start-period=1s \
45
- --health-retries=10 \
46
- --health-interval=1s \
47
- -p 9091:9091 \
48
- ${NODE_CONTAINER_NAME}:${BUILD_ID}
49
-
50
- COUNTER=0
51
- echo "$NODE_CONTAINER_NAME container status"
52
- until [ "$(docker inspect -f {{.State.Health.Status}} $NODE_CONTAINER_NAME)" = "healthy" ]; do
53
- sleep 1
54
- docker inspect -f {{.State.Health.Status}} $NODE_CONTAINER_NAME
55
- COUNTER=$((COUNTER + 1))
56
- if [ $COUNTER -ge $MAX_RETRIES ]; then
57
- echo "Exceeded maximum retries. Exiting."
58
- ERROR_CODE=1
59
- break
60
- fi
61
- done
62
- fi
63
-
64
- if [[ $ERROR_CODE -eq 0 ]]; then
65
- sleep 2
66
- curl -X GET -f http://localhost:9091/api/dummy -H 'Content-Type: application/json'
67
- sleep 2
68
- curl -X GET -f http://localhost:9091/api/dummy -H 'Content-Type: application/json'
69
- fi
70
-
71
- # sleep N seconds to await instrumentation flow send and receiving signals
72
- sleep 1
73
-
74
- # Copy logs from container to file
75
- docker container logs $ALLOY_CONTAINER_NAME >&$ROOT_PATH/packages/sdk-node/test/integration/logs.txt
76
- echo "log file at $ROOT_PATH/packages/sdk-node/test/integration/logs.txt"
77
-
78
- docker container stop $ALLOY_CONTAINER_NAME
79
- docker container stop $NODE_CONTAINER_NAME
80
-
81
- docker container rm -f $ALLOY_CONTAINER_NAME
82
- docker container rm -f $NODE_CONTAINER_NAME
83
-
84
- docker image rm ${NODE_CONTAINER_NAME}:${BUILD_ID}
85
-
86
- docker network rm $NETWORK_NAME
87
-
88
- exit $ERROR_CODE