From 8c81e58303efeb9fe408b889da6c74e3be672053 Mon Sep 17 00:00:00 2001 From: Milan Suk Date: Tue, 10 Oct 2023 01:30:37 +0200 Subject: [PATCH] feat: allow log annotations to be any object (#1500) Co-authored-by: Tim --- .changeset/cuddly-mayflies-warn.md | 5 + .changeset/flat-hounds-impress.md | 5 + .changeset/selfish-wolves-watch.md | 5 + .changeset/shiny-jokes-kick.md | 5 + docs/modules/Effect.ts.md | 2 +- docs/modules/FiberRef.ts.md | 2 +- docs/modules/Logger.ts.md | 2 +- package.json | 6 +- pnpm-lock.yaml | 193 +++++++++++++++++++---------- scripts/clean.mjs | 8 +- src/Channel.ts | 4 +- src/Effect.ts | 45 ++++--- src/FiberRef.ts | 5 +- src/Layer.ts | 4 +- src/Logger.ts | 10 +- src/Stream.ts | 4 +- src/Tracer.ts | 27 ++-- src/internal/channel.ts | 4 +- src/internal/core-effect.ts | 45 +++---- src/internal/core.ts | 12 +- src/internal/fiberRuntime.ts | 7 +- src/internal/layer.ts | 4 +- src/internal/layer/circular.ts | 2 +- src/internal/logger.ts | 8 +- src/internal/stream.ts | 4 +- src/internal/tracer.ts | 33 ++++- test/Logger.ts | 35 +++++- test/Tracer.ts | 3 + 28 files changed, 309 insertions(+), 180 deletions(-) create mode 100644 .changeset/cuddly-mayflies-warn.md create mode 100644 .changeset/flat-hounds-impress.md create mode 100644 .changeset/selfish-wolves-watch.md create mode 100644 .changeset/shiny-jokes-kick.md diff --git a/.changeset/cuddly-mayflies-warn.md b/.changeset/cuddly-mayflies-warn.md new file mode 100644 index 0000000000..7125434280 --- /dev/null +++ b/.changeset/cuddly-mayflies-warn.md @@ -0,0 +1,5 @@ +--- +"effect": minor +--- + +Allow log annotations to be any object. diff --git a/.changeset/flat-hounds-impress.md b/.changeset/flat-hounds-impress.md new file mode 100644 index 0000000000..dc4da1fe3c --- /dev/null +++ b/.changeset/flat-hounds-impress.md @@ -0,0 +1,5 @@ +--- +"effect": patch +--- + +allow tracing attributes to be unknown diff --git a/.changeset/selfish-wolves-watch.md b/.changeset/selfish-wolves-watch.md new file mode 100644 index 0000000000..25725cd223 --- /dev/null +++ b/.changeset/selfish-wolves-watch.md @@ -0,0 +1,5 @@ +--- +"effect": minor +--- + +add sampled flag to spans diff --git a/.changeset/shiny-jokes-kick.md b/.changeset/shiny-jokes-kick.md new file mode 100644 index 0000000000..51393d5573 --- /dev/null +++ b/.changeset/shiny-jokes-kick.md @@ -0,0 +1,5 @@ +--- +"effect": patch +--- + +add Tracer.externalSpan constructor diff --git a/docs/modules/Effect.ts.md b/docs/modules/Effect.ts.md index 6287890da3..d8ca190b29 100644 --- a/docs/modules/Effect.ts.md +++ b/docs/modules/Effect.ts.md @@ -3336,7 +3336,7 @@ Retrieves the log annotations associated with the current scope. **Signature** ```ts -export declare const logAnnotations: Effect> +export declare const logAnnotations: Effect> ``` Added in v2.0.0 diff --git a/docs/modules/FiberRef.ts.md b/docs/modules/FiberRef.ts.md index f64fca1739..0a6a80b715 100644 --- a/docs/modules/FiberRef.ts.md +++ b/docs/modules/FiberRef.ts.md @@ -205,7 +205,7 @@ Added in v2.0.0 **Signature** ```ts -export declare const currentLogAnnotations: FiberRef> +export declare const currentLogAnnotations: FiberRef> ``` Added in v2.0.0 diff --git a/docs/modules/Logger.ts.md b/docs/modules/Logger.ts.md index d72d536ab2..27a55add72 100644 --- a/docs/modules/Logger.ts.md +++ b/docs/modules/Logger.ts.md @@ -360,7 +360,7 @@ Added in v2.0.0 **Signature** ```ts -export type AnnotationValue = string | number | boolean +export type AnnotationValue = unknown ``` Added in v2.0.0 diff --git a/package.json b/package.json index 2bf2eee452..2bb29b7c63 100644 --- a/package.json +++ b/package.json @@ -1077,9 +1077,9 @@ "@effect/language-service": "^0.0.21", "@preconstruct/cli": "^2.8.1", "@types/chai": "^4.3.6", - "@types/node": "^20.8.3", - "@typescript-eslint/eslint-plugin": "^6.7.4", - "@typescript-eslint/parser": "^6.7.4", + "@types/node": "^20.8.4", + "@typescript-eslint/eslint-plugin": "^6.7.5", + "@typescript-eslint/parser": "^6.7.5", "@vitejs/plugin-react": "^4.1.0", "@vitest/coverage-v8": "^0.34.6", "@vitest/expect": "^0.34.6", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2470c913bc..35ed02594a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -30,7 +30,7 @@ devDependencies: version: 0.1.8 '@effect/docgen': specifier: ^0.1.8 - version: 0.1.8(@types/node@20.8.3)(typescript@5.2.2) + version: 0.1.8(@types/node@20.8.4)(typescript@5.2.2) '@effect/eslint-plugin': specifier: ^0.1.2 version: 0.1.2 @@ -44,14 +44,14 @@ devDependencies: specifier: ^4.3.6 version: 4.3.6 '@types/node': - specifier: ^20.8.3 - version: 20.8.3 + specifier: ^20.8.4 + version: 20.8.4 '@typescript-eslint/eslint-plugin': - specifier: ^6.7.4 - version: 6.7.4(@typescript-eslint/parser@6.7.4)(eslint@8.51.0)(typescript@5.2.2) + specifier: ^6.7.5 + version: 6.7.5(@typescript-eslint/parser@6.7.5)(eslint@8.51.0)(typescript@5.2.2) '@typescript-eslint/parser': - specifier: ^6.7.4 - version: 6.7.4(eslint@8.51.0)(typescript@5.2.2) + specifier: ^6.7.5 + version: 6.7.5(eslint@8.51.0)(typescript@5.2.2) '@vitejs/plugin-react': specifier: ^4.1.0 version: 4.1.0(vite@4.4.11) @@ -69,7 +69,7 @@ devDependencies: version: 8.51.0 eslint-import-resolver-typescript: specifier: ^3.6.1 - version: 3.6.1(@typescript-eslint/parser@6.7.4)(eslint-plugin-import@2.28.1)(eslint@8.51.0) + version: 3.6.1(@typescript-eslint/parser@6.7.5)(eslint-plugin-import@2.28.1)(eslint@8.51.0) eslint-plugin-codegen: specifier: 0.17.0 version: 0.17.0 @@ -78,7 +78,7 @@ devDependencies: version: 2.0.0(eslint@8.51.0)(typescript@5.2.2) eslint-plugin-import: specifier: ^2.28.1 - version: 2.28.1(@typescript-eslint/parser@6.7.4)(eslint-import-resolver-typescript@3.6.1)(eslint@8.51.0) + version: 2.28.1(@typescript-eslint/parser@6.7.5)(eslint-import-resolver-typescript@3.6.1)(eslint@8.51.0) eslint-plugin-simple-import-sort: specifier: ^10.0.0 version: 10.0.0(eslint@8.51.0) @@ -96,13 +96,13 @@ devDependencies: version: 3.0.3 ts-node: specifier: ^10.9.1 - version: 10.9.1(@types/node@20.8.3)(typescript@5.2.2) + version: 10.9.1(@types/node@20.8.4)(typescript@5.2.2) typescript: specifier: ^5.2.2 version: 5.2.2 vite: specifier: ^4.4.11 - version: 4.4.11(@types/node@20.8.3) + version: 4.4.11(@types/node@20.8.4) vitest: specifier: 0.34.6 version: 0.34.6 @@ -785,7 +785,7 @@ packages: hasBin: true dev: true - /@effect/docgen@0.1.8(@types/node@20.8.3)(typescript@5.2.2): + /@effect/docgen@0.1.8(@types/node@20.8.4)(typescript@5.2.2): resolution: {integrity: sha512-o3iLXvbkkxEuRUnJ6hJDEXHfeDfA86iVkQm/s8heWQQgD7UBZ7TTWkDIobFaXRKU8qKoCKPSgmLlSq0F3IsBgw==} engines: {node: '>=16.17.1'} hasBin: true @@ -799,7 +799,7 @@ packages: prettier: 2.8.8 rimraf: 5.0.1 ts-morph: 19.0.0 - ts-node: 10.9.1(@types/node@20.8.3)(typescript@5.2.2) + ts-node: 10.9.1(@types/node@20.8.4)(typescript@5.2.2) tsconfck: 2.1.2(typescript@5.2.2) typescript: 5.2.2 transitivePeerDependencies: @@ -1105,7 +1105,7 @@ packages: dependencies: '@types/istanbul-lib-coverage': 2.0.4 '@types/istanbul-reports': 3.0.1 - '@types/node': 20.8.3 + '@types/node': 20.8.4 '@types/yargs': 15.0.16 chalk: 4.1.2 dev: true @@ -1265,7 +1265,7 @@ packages: dependencies: concat-stream: 2.0.0 graceful-fs: 4.2.11 - normalize-package-data: 3.0.3 + normalize-package-data: 2.5.0 npm-package-arg: 8.1.5 once: 1.4.0 request: 2.88.2 @@ -1468,8 +1468,10 @@ packages: resolution: {integrity: sha512-fAtCfv4jJg+ExtXhvCkCqUKZ+4ok/JQk01qDKhL5BDDoS3AxKXhV5/MAVUZyQnSEd2GT92fkgZl0pz0Q0AzcIQ==} dev: true - /@types/node@20.8.3: - resolution: {integrity: sha512-jxiZQFpb+NlH5kjW49vXxvxTjeeqlbsnTAdBTKpzEdPs9itay7MscYXz3Fo9VYFEsfQ6LJFitHad3faerLAjCw==} + /@types/node@20.8.4: + resolution: {integrity: sha512-ZVPnqU58giiCjSxjVUESDtdPk4QR5WQhhINbc9UBrKLU68MX5BF6kbQzTrkwbolyr0X8ChBpXfavr5mZFKZQ5A==} + dependencies: + undici-types: 5.25.3 dev: true /@types/normalize-package-data@2.4.2: @@ -1483,7 +1485,7 @@ packages: /@types/resolve@1.17.1: resolution: {integrity: sha512-yy7HuzQhj0dhGpD8RLXSZWEkLsV9ibvxvi6EiJ3bkqLAO1RGo0WbkWQiwpRlSFymTJRz0d3k5LM3kkx8ArDbLw==} dependencies: - '@types/node': 20.8.3 + '@types/node': 20.8.4 dev: true /@types/semver@7.5.2: @@ -1536,8 +1538,8 @@ packages: - supports-color dev: true - /@typescript-eslint/eslint-plugin@6.7.4(@typescript-eslint/parser@6.7.4)(eslint@8.51.0)(typescript@5.2.2): - resolution: {integrity: sha512-DAbgDXwtX+pDkAHwiGhqP3zWUGpW49B7eqmgpPtg+BKJXwdct79ut9+ifqOFPJGClGKSHXn2PTBatCnldJRUoA==} + /@typescript-eslint/eslint-plugin@6.7.5(@typescript-eslint/parser@6.7.5)(eslint@8.51.0)(typescript@5.2.2): + resolution: {integrity: sha512-JhtAwTRhOUcP96D0Y6KYnwig/MRQbOoLGXTON2+LlyB/N35SP9j1boai2zzwXb7ypKELXMx3DVk9UTaEq1vHEw==} engines: {node: ^16.0.0 || >=18.0.0} peerDependencies: '@typescript-eslint/parser': ^6.0.0 || ^6.0.0-alpha @@ -1548,11 +1550,11 @@ packages: optional: true dependencies: '@eslint-community/regexpp': 4.9.1 - '@typescript-eslint/parser': 6.7.4(eslint@8.51.0)(typescript@5.2.2) - '@typescript-eslint/scope-manager': 6.7.4 - '@typescript-eslint/type-utils': 6.7.4(eslint@8.51.0)(typescript@5.2.2) - '@typescript-eslint/utils': 6.7.4(eslint@8.51.0)(typescript@5.2.2) - '@typescript-eslint/visitor-keys': 6.7.4 + '@typescript-eslint/parser': 6.7.5(eslint@8.51.0)(typescript@5.2.2) + '@typescript-eslint/scope-manager': 6.7.5 + '@typescript-eslint/type-utils': 6.7.5(eslint@8.51.0)(typescript@5.2.2) + '@typescript-eslint/utils': 6.7.5(eslint@8.51.0)(typescript@5.2.2) + '@typescript-eslint/visitor-keys': 6.7.5 debug: 4.3.4 eslint: 8.51.0 graphemer: 1.4.0 @@ -1585,8 +1587,8 @@ packages: - supports-color dev: true - /@typescript-eslint/parser@6.7.4(eslint@8.51.0)(typescript@5.2.2): - resolution: {integrity: sha512-I5zVZFY+cw4IMZUeNCU7Sh2PO5O57F7Lr0uyhgCJmhN/BuTlnc55KxPonR4+EM3GBdfiCyGZye6DgMjtubQkmA==} + /@typescript-eslint/parser@6.7.5(eslint@8.51.0)(typescript@5.2.2): + resolution: {integrity: sha512-bIZVSGx2UME/lmhLcjdVc7ePBwn7CLqKarUBL4me1C5feOd663liTGjMBGVcGr+BhnSLeP4SgwdvNnnkbIdkCw==} engines: {node: ^16.0.0 || >=18.0.0} peerDependencies: eslint: ^7.0.0 || ^8.0.0 @@ -1595,10 +1597,10 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/scope-manager': 6.7.4 - '@typescript-eslint/types': 6.7.4 - '@typescript-eslint/typescript-estree': 6.7.4(typescript@5.2.2) - '@typescript-eslint/visitor-keys': 6.7.4 + '@typescript-eslint/scope-manager': 6.7.5 + '@typescript-eslint/types': 6.7.5 + '@typescript-eslint/typescript-estree': 6.7.5(typescript@5.2.2) + '@typescript-eslint/visitor-keys': 6.7.5 debug: 4.3.4 eslint: 8.51.0 typescript: 5.2.2 @@ -1622,6 +1624,14 @@ packages: '@typescript-eslint/visitor-keys': 6.7.4 dev: true + /@typescript-eslint/scope-manager@6.7.5: + resolution: {integrity: sha512-GAlk3eQIwWOJeb9F7MKQ6Jbah/vx1zETSDw8likab/eFcqkjSD7BI75SDAeC5N2L0MmConMoPvTsmkrg71+B1A==} + engines: {node: ^16.0.0 || >=18.0.0} + dependencies: + '@typescript-eslint/types': 6.7.5 + '@typescript-eslint/visitor-keys': 6.7.5 + dev: true + /@typescript-eslint/type-utils@5.62.0(eslint@8.51.0)(typescript@5.2.2): resolution: {integrity: sha512-xsSQreu+VnfbqQpW5vnCJdq1Z3Q0U31qiWmRhr98ONQmcp/yhiPJFPq8MXiJVLiksmOKSjIldZzkebzHuCGzew==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} @@ -1642,8 +1652,8 @@ packages: - supports-color dev: true - /@typescript-eslint/type-utils@6.7.4(eslint@8.51.0)(typescript@5.2.2): - resolution: {integrity: sha512-n+g3zi1QzpcAdHFP9KQF+rEFxMb2KxtnJGID3teA/nxKHOVi3ylKovaqEzGBbVY2pBttU6z85gp0D00ufLzViQ==} + /@typescript-eslint/type-utils@6.7.5(eslint@8.51.0)(typescript@5.2.2): + resolution: {integrity: sha512-Gs0qos5wqxnQrvpYv+pf3XfcRXW6jiAn9zE/K+DlmYf6FcpxeNYN0AIETaPR7rHO4K2UY+D0CIbDP9Ut0U4m1g==} engines: {node: ^16.0.0 || >=18.0.0} peerDependencies: eslint: ^7.0.0 || ^8.0.0 @@ -1652,8 +1662,8 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/typescript-estree': 6.7.4(typescript@5.2.2) - '@typescript-eslint/utils': 6.7.4(eslint@8.51.0)(typescript@5.2.2) + '@typescript-eslint/typescript-estree': 6.7.5(typescript@5.2.2) + '@typescript-eslint/utils': 6.7.5(eslint@8.51.0)(typescript@5.2.2) debug: 4.3.4 eslint: 8.51.0 ts-api-utils: 1.0.3(typescript@5.2.2) @@ -1677,6 +1687,11 @@ packages: engines: {node: ^16.0.0 || >=18.0.0} dev: true + /@typescript-eslint/types@6.7.5: + resolution: {integrity: sha512-WboQBlOXtdj1tDFPyIthpKrUb+kZf2VroLZhxKa/VlwLlLyqv/PwUNgL30BlTVZV1Wu4Asu2mMYPqarSO4L5ZQ==} + engines: {node: ^16.0.0 || >=18.0.0} + dev: true + /@typescript-eslint/typescript-estree@4.33.0(typescript@3.9.10): resolution: {integrity: sha512-rkWRY1MPFzjwnEVHsxGemDzqqddw2QbTJlICPD9p9I9LfsO8fdmfQPOX3uKfUaGRDFJbfrtm/sXhVXN4E+bzCA==} engines: {node: ^10.12.0 || >=12.0.0} @@ -1761,6 +1776,27 @@ packages: - supports-color dev: true + /@typescript-eslint/typescript-estree@6.7.5(typescript@5.2.2): + resolution: {integrity: sha512-NhJiJ4KdtwBIxrKl0BqG1Ur+uw7FiOnOThcYx9DpOGJ/Abc9z2xNzLeirCG02Ig3vkvrc2qFLmYSSsaITbKjlg==} + engines: {node: ^16.0.0 || >=18.0.0} + peerDependencies: + typescript: '*' + peerDependenciesMeta: + typescript: + optional: true + dependencies: + '@typescript-eslint/types': 6.7.5 + '@typescript-eslint/visitor-keys': 6.7.5 + debug: 4.3.4 + globby: 11.1.0 + is-glob: 4.0.3 + semver: 7.5.4 + ts-api-utils: 1.0.3(typescript@5.2.2) + typescript: 5.2.2 + transitivePeerDependencies: + - supports-color + dev: true + /@typescript-eslint/utils@5.62.0(eslint@8.51.0)(typescript@5.2.2): resolution: {integrity: sha512-n8oxjeb5aIbPFEtmQxQYOLI0i9n5ySBEY/ZEHHZqKQSFnxio1rv6dthascc9dLuwrL0RC5mPCxB7vnAVGAYWAQ==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} @@ -1800,6 +1836,25 @@ packages: - typescript dev: true + /@typescript-eslint/utils@6.7.5(eslint@8.51.0)(typescript@5.2.2): + resolution: {integrity: sha512-pfRRrH20thJbzPPlPc4j0UNGvH1PjPlhlCMq4Yx7EGjV7lvEeGX0U6MJYe8+SyFutWgSHsdbJ3BXzZccYggezA==} + engines: {node: ^16.0.0 || >=18.0.0} + peerDependencies: + eslint: ^7.0.0 || ^8.0.0 + dependencies: + '@eslint-community/eslint-utils': 4.4.0(eslint@8.51.0) + '@types/json-schema': 7.0.13 + '@types/semver': 7.5.3 + '@typescript-eslint/scope-manager': 6.7.5 + '@typescript-eslint/types': 6.7.5 + '@typescript-eslint/typescript-estree': 6.7.5(typescript@5.2.2) + eslint: 8.51.0 + semver: 7.5.4 + transitivePeerDependencies: + - supports-color + - typescript + dev: true + /@typescript-eslint/visitor-keys@4.33.0: resolution: {integrity: sha512-uqi/2aSz9g2ftcHWf8uLPJA70rUv6yuMW5Bohw+bwcuzaxQIHaKFZCKGoGXIrc9vkTJ3+0txM73K0Hq3d5wgIg==} engines: {node: ^8.10.0 || ^10.13.0 || >=11.10.1} @@ -1824,6 +1879,14 @@ packages: eslint-visitor-keys: 3.4.3 dev: true + /@typescript-eslint/visitor-keys@6.7.5: + resolution: {integrity: sha512-3MaWdDZtLlsexZzDSdQWsFQ9l9nL8B80Z4fImSpyllFC/KLqWQRdEcB+gGGO+N3Q2uL40EsG66wZLsohPxNXvg==} + engines: {node: ^16.0.0 || >=18.0.0} + dependencies: + '@typescript-eslint/types': 6.7.5 + eslint-visitor-keys: 3.4.3 + dev: true + /@vitejs/plugin-react@4.1.0(vite@4.4.11): resolution: {integrity: sha512-rM0SqazU9iqPUraQ2JlIvReeaxOoRj6n+PzB1C0cBzIbd8qP336nC39/R9yPi3wVcah7E7j/kdU1uCUqMEU4OQ==} engines: {node: ^14.18.0 || >=16.0.0} @@ -1835,7 +1898,7 @@ packages: '@babel/plugin-transform-react-jsx-source': 7.22.5(@babel/core@7.23.0) '@types/babel__core': 7.20.2 react-refresh: 0.14.0 - vite: 4.4.11(@types/node@20.8.3) + vite: 4.4.11(@types/node@20.8.4) transitivePeerDependencies: - supports-color dev: true @@ -2504,6 +2567,7 @@ packages: /core-util-is@1.0.3: resolution: {integrity: sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==} + requiresBuild: true dev: true /create-require@1.1.1: @@ -3077,7 +3141,7 @@ packages: - supports-color dev: true - /eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.7.4)(eslint-plugin-import@2.28.1)(eslint@8.51.0): + /eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.7.5)(eslint-plugin-import@2.28.1)(eslint@8.51.0): resolution: {integrity: sha512-xgdptdoi5W3niYeuQxKmzVDTATvLYqhpwmykwsh7f6HIOStGWEIL9iqZgQDF9u9OEzrRwR8no5q2VT+bjAujTg==} engines: {node: ^14.18.0 || >=16.0.0} peerDependencies: @@ -3087,8 +3151,8 @@ packages: debug: 4.3.4 enhanced-resolve: 5.15.0 eslint: 8.51.0 - eslint-module-utils: 2.8.0(@typescript-eslint/parser@6.7.4)(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1)(eslint@8.51.0) - eslint-plugin-import: 2.28.1(@typescript-eslint/parser@6.7.4)(eslint-import-resolver-typescript@3.6.1)(eslint@8.51.0) + eslint-module-utils: 2.8.0(@typescript-eslint/parser@6.7.5)(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1)(eslint@8.51.0) + eslint-plugin-import: 2.28.1(@typescript-eslint/parser@6.7.5)(eslint-import-resolver-typescript@3.6.1)(eslint@8.51.0) fast-glob: 3.3.1 get-tsconfig: 4.7.2 is-core-module: 2.13.0 @@ -3100,7 +3164,7 @@ packages: - supports-color dev: true - /eslint-module-utils@2.8.0(@typescript-eslint/parser@6.7.4)(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1)(eslint@8.51.0): + /eslint-module-utils@2.8.0(@typescript-eslint/parser@6.7.5)(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1)(eslint@8.51.0): resolution: {integrity: sha512-aWajIYfsqCKRDgUfjEXNN/JlrzauMuSEy5sbd7WXbtW3EH6A6MpwEh42c7qD+MqQo9QMJ6fWLAeIJynx0g6OAw==} engines: {node: '>=4'} peerDependencies: @@ -3121,11 +3185,11 @@ packages: eslint-import-resolver-webpack: optional: true dependencies: - '@typescript-eslint/parser': 6.7.4(eslint@8.51.0)(typescript@5.2.2) + '@typescript-eslint/parser': 6.7.5(eslint@8.51.0)(typescript@5.2.2) debug: 3.2.7 eslint: 8.51.0 eslint-import-resolver-node: 0.3.9 - eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@6.7.4)(eslint-plugin-import@2.28.1)(eslint@8.51.0) + eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@6.7.5)(eslint-plugin-import@2.28.1)(eslint@8.51.0) transitivePeerDependencies: - supports-color dev: true @@ -3165,7 +3229,7 @@ packages: - supports-color dev: true - /eslint-plugin-import@2.28.1(@typescript-eslint/parser@6.7.4)(eslint-import-resolver-typescript@3.6.1)(eslint@8.51.0): + /eslint-plugin-import@2.28.1(@typescript-eslint/parser@6.7.5)(eslint-import-resolver-typescript@3.6.1)(eslint@8.51.0): resolution: {integrity: sha512-9I9hFlITvOV55alzoKBI+K9q74kv0iKMeY6av5+umsNwayt59fz692daGyjR+oStBQgx6nwR9rXldDev3Clw+A==} engines: {node: '>=4'} peerDependencies: @@ -3175,7 +3239,7 @@ packages: '@typescript-eslint/parser': optional: true dependencies: - '@typescript-eslint/parser': 6.7.4(eslint@8.51.0)(typescript@5.2.2) + '@typescript-eslint/parser': 6.7.5(eslint@8.51.0)(typescript@5.2.2) array-includes: 3.1.7 array.prototype.findlastindex: 1.2.3 array.prototype.flat: 1.3.2 @@ -3184,7 +3248,7 @@ packages: doctrine: 2.1.0 eslint: 8.51.0 eslint-import-resolver-node: 0.3.9 - eslint-module-utils: 2.8.0(@typescript-eslint/parser@6.7.4)(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1)(eslint@8.51.0) + eslint-module-utils: 2.8.0(@typescript-eslint/parser@6.7.5)(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1)(eslint@8.51.0) has: 1.0.3 is-core-module: 2.13.0 is-glob: 4.0.3 @@ -4424,7 +4488,7 @@ packages: resolution: {integrity: sha512-KWYVV1c4i+jbMpaBC+U++4Va0cp8OisU185o73T1vo99hqi7w8tSJfUXYswwqqrjzwxa6KpRK54WhPvwf5w6PQ==} engines: {node: '>= 10.13.0'} dependencies: - '@types/node': 20.8.3 + '@types/node': 20.8.4 merge-stream: 2.0.0 supports-color: 7.2.0 dev: true @@ -5043,16 +5107,6 @@ packages: validate-npm-package-license: 3.0.4 dev: true - /normalize-package-data@3.0.3: - resolution: {integrity: sha512-p2W1sgqij3zMMyRC067Dg16bfzVH+w7hyegmpIvZ4JNjqtGOVAIvLmjBx3yP7YTe9vKJgkoNOPjwQGogDoMXFA==} - engines: {node: '>=10'} - dependencies: - hosted-git-info: 4.1.0 - is-core-module: 2.13.0 - semver: 7.5.4 - validate-npm-package-license: 3.0.4 - dev: true - /normalize-path@3.0.0: resolution: {integrity: sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==} engines: {node: '>=0.10.0'} @@ -5531,6 +5585,7 @@ packages: /process-nextick-args@2.0.1: resolution: {integrity: sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==} + requiresBuild: true dev: true /pseudomap@1.0.2: @@ -5847,6 +5902,7 @@ packages: /safe-buffer@5.1.2: resolution: {integrity: sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==} + requiresBuild: true dev: true /safe-buffer@5.2.1: @@ -6158,6 +6214,7 @@ packages: /string_decoder@1.1.1: resolution: {integrity: sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==} + requiresBuild: true dependencies: safe-buffer: 5.1.2 dev: true @@ -6420,7 +6477,7 @@ packages: code-block-writer: 12.0.0 dev: true - /ts-node@10.9.1(@types/node@20.8.3)(typescript@5.2.2): + /ts-node@10.9.1(@types/node@20.8.4)(typescript@5.2.2): resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==} hasBin: true peerDependencies: @@ -6439,7 +6496,7 @@ packages: '@tsconfig/node12': 1.0.11 '@tsconfig/node14': 1.0.3 '@tsconfig/node16': 1.0.4 - '@types/node': 20.8.3 + '@types/node': 20.8.4 acorn: 8.10.0 acorn-walk: 8.2.0 arg: 4.1.3 @@ -6672,6 +6729,10 @@ packages: which-boxed-primitive: 1.0.2 dev: true + /undici-types@5.25.3: + resolution: {integrity: sha512-Ga1jfYwRn7+cP9v8auvEXN1rX3sWqlayd4HP7OKk4mZWylEmu3KzXDUGrQUN6Ol7qo1gPvB2e5gX6udnyEPgdA==} + dev: true + /uniq@1.0.1: resolution: {integrity: sha512-Gw+zz50YNKPDKXs+9d+aKAjVwpjNwqzvNpLigIruT4HA9lMZNdMqs9x07kKHB/L9WRzqp4+DlTU5s4wG2esdoA==} dev: true @@ -6752,7 +6813,7 @@ packages: extsprintf: 1.3.0 dev: true - /vite-node@0.34.6(@types/node@20.8.3): + /vite-node@0.34.6(@types/node@20.8.4): resolution: {integrity: sha512-nlBMJ9x6n7/Amaz6F3zJ97EBwR2FkzhBRxF5e+jE6LA3yi6Wtc2lyTij1OnDMIr34v5g/tVQtsVAzhT0jc5ygA==} engines: {node: '>=v14.18.0'} hasBin: true @@ -6762,7 +6823,7 @@ packages: mlly: 1.4.2 pathe: 1.1.1 picocolors: 1.0.0 - vite: 4.4.11(@types/node@20.8.3) + vite: 4.4.11(@types/node@20.8.4) transitivePeerDependencies: - '@types/node' - less @@ -6774,7 +6835,7 @@ packages: - terser dev: true - /vite@4.4.11(@types/node@20.8.3): + /vite@4.4.11(@types/node@20.8.4): resolution: {integrity: sha512-ksNZJlkcU9b0lBwAGZGGaZHCMqHsc8OpgtoYhsQ4/I2v5cnpmmmqe5pM4nv/4Hn6G/2GhTdj0DhZh2e+Er1q5A==} engines: {node: ^14.18.0 || >=16.0.0} hasBin: true @@ -6802,7 +6863,7 @@ packages: terser: optional: true dependencies: - '@types/node': 20.8.3 + '@types/node': 20.8.4 esbuild: 0.18.20 postcss: 8.4.31 rollup: 3.29.4 @@ -6843,7 +6904,7 @@ packages: dependencies: '@types/chai': 4.3.6 '@types/chai-subset': 1.3.3 - '@types/node': 20.8.3 + '@types/node': 20.8.4 '@vitest/expect': 0.34.6 '@vitest/runner': 0.34.6 '@vitest/snapshot': 0.34.6 @@ -6862,8 +6923,8 @@ packages: strip-literal: 1.3.0 tinybench: 2.5.1 tinypool: 0.7.0 - vite: 4.4.11(@types/node@20.8.3) - vite-node: 0.34.6(@types/node@20.8.3) + vite: 4.4.11(@types/node@20.8.4) + vite-node: 0.34.6(@types/node@20.8.4) why-is-node-running: 2.2.2 transitivePeerDependencies: - less @@ -6958,7 +7019,7 @@ packages: resolution: {integrity: sha512-eDMORYaPNZ4sQIuuYPDHdQvf4gyCF9rEEV/yPxGfwPkRodwEgiMUUXTx/dex+Me0wxx53S+NgUHaP7y3MGlDmg==} requiresBuild: true dependencies: - string-width: 1.0.2 + string-width: 4.2.3 dev: true optional: true diff --git a/scripts/clean.mjs b/scripts/clean.mjs index 606fc50b9c..31f606bcba 100644 --- a/scripts/clean.mjs +++ b/scripts/clean.mjs @@ -1,8 +1,8 @@ import * as Fs from "node:fs"; import Package from "../package.json" assert { type: "json" }; -Package.files - .filter((_) => _ !== "src") - .forEach((file) => { +["src/tsconfig.json", ...Package.files.filter((_) => _ !== "src")].forEach( + (file) => { Fs.rm(file, { recursive: true, force: true }, () => {}); - }); + } +); diff --git a/src/Channel.ts b/src/Channel.ts index 6039cf9e2e..7eaa2b3067 100644 --- a/src/Channel.ts +++ b/src/Channel.ts @@ -2060,7 +2060,7 @@ export const withSpan: { ( name: string, options?: { - readonly attributes?: Record + readonly attributes?: Record readonly links?: ReadonlyArray readonly parent?: Tracer.ParentSpan readonly root?: boolean @@ -2073,7 +2073,7 @@ export const withSpan: { self: Channel, name: string, options?: { - readonly attributes?: Record + readonly attributes?: Record readonly links?: ReadonlyArray readonly parent?: Tracer.ParentSpan readonly root?: boolean diff --git a/src/Effect.ts b/src/Effect.ts index d24a372d6b..1a01be806a 100644 --- a/src/Effect.ts +++ b/src/Effect.ts @@ -37,7 +37,6 @@ import * as query from "./internal/query" import * as _runtime from "./internal/runtime" import * as _schedule from "./internal/schedule" import type * as Layer from "./Layer" -import type * as Logger from "./Logger" import type { LogLevel } from "./LogLevel" import type * as Metric from "./Metric" import type * as MetricLabel from "./MetricLabel" @@ -4265,10 +4264,10 @@ export const withLogSpan: { * @category logging */ export const annotateLogs: { - (key: string, value: Logger.AnnotationValue): (effect: Effect) => Effect - (values: Record): (effect: Effect) => Effect - (effect: Effect, key: string, value: Logger.AnnotationValue): Effect - (effect: Effect, values: Record): Effect + (key: string, value: unknown): (effect: Effect) => Effect + (values: Record): (effect: Effect) => Effect + (effect: Effect, key: string, value: unknown): Effect + (effect: Effect, values: Record): Effect } = effect.annotateLogs /** @@ -4277,8 +4276,7 @@ export const annotateLogs: { * @since 2.0.0 * @category logging */ -export const logAnnotations: Effect> = - effect.logAnnotations +export const logAnnotations: Effect> = effect.logAnnotations /** * Decides wether child fibers will report or not unhandled errors via the logger @@ -4947,10 +4945,10 @@ export const setTracerTiming: (enabled: boolean) => Layer.Layer(effect: Effect) => Effect - (values: Record): (effect: Effect) => Effect - (effect: Effect, key: string, value: Tracer.AttributeValue): Effect - (effect: Effect, values: Record): Effect + (key: string, value: unknown): (effect: Effect) => Effect + (values: Record): (effect: Effect) => Effect + (effect: Effect, key: string, value: unknown): Effect + (effect: Effect, values: Record): Effect } = effect.annotateSpans /** @@ -4960,8 +4958,8 @@ export const annotateSpans: { * @category tracing */ export const annotateCurrentSpan: { - (key: string, value: Tracer.AttributeValue): Effect - (values: Record): Effect + (key: string, value: unknown): Effect + (values: Record): Effect } = effect.annotateCurrentSpan /** @@ -4980,8 +4978,7 @@ export const currentParentSpan: Effect> = - effect.spanAnnotations +export const spanAnnotations: Effect> = effect.spanAnnotations /** * @since 2.0.0 @@ -4998,12 +4995,12 @@ export const spanLinks: Effect> = eff export const linkSpans: { ( span: Tracer.ParentSpan, - attributes?: Record + attributes?: Record ): (self: Effect) => Effect ( self: Effect, span: Tracer.ParentSpan, - attributes?: Record + attributes?: Record ): Effect } = effect.linkSpans @@ -5016,7 +5013,7 @@ export const linkSpans: { export const makeSpan: ( name: string, options?: { - readonly attributes?: Record + readonly attributes?: Record readonly links?: ReadonlyArray readonly parent?: Tracer.ParentSpan readonly root?: boolean @@ -5043,7 +5040,7 @@ export const setParentSpan: (span: Tracer.ParentSpan) => Layer.Layer + readonly attributes?: Record readonly links?: ReadonlyArray readonly parent?: Tracer.ParentSpan readonly root?: boolean @@ -5066,7 +5063,7 @@ export const useSpan: { ( name: string, options: { - readonly attributes?: Record + readonly attributes?: Record readonly links?: ReadonlyArray readonly parent?: Tracer.ParentSpan readonly root?: boolean @@ -5089,7 +5086,7 @@ export const useSpan: { export const useSpanScoped: ( name: string, options?: { - readonly attributes?: Record + readonly attributes?: Record readonly links?: ReadonlyArray readonly parent?: Tracer.ParentSpan readonly root?: boolean @@ -5107,7 +5104,7 @@ export const withSpan: { ( name: string, options?: { - readonly attributes?: Record + readonly attributes?: Record readonly links?: ReadonlyArray readonly parent?: Tracer.ParentSpan readonly root?: boolean @@ -5118,7 +5115,7 @@ export const withSpan: { self: Effect, name: string, options?: { - readonly attributes?: Record + readonly attributes?: Record readonly links?: ReadonlyArray readonly parent?: Tracer.ParentSpan readonly root?: boolean @@ -5138,7 +5135,7 @@ export const withSpan: { export const withSpanScoped: ( name: string, options?: { - readonly attributes?: Record + readonly attributes?: Record readonly links?: ReadonlyArray readonly parent?: Tracer.ParentSpan readonly root?: boolean diff --git a/src/FiberRef.ts b/src/FiberRef.ts index 12117e4ba3..b84e5df025 100644 --- a/src/FiberRef.ts +++ b/src/FiberRef.ts @@ -316,8 +316,7 @@ export const unhandledErrorLogLevel: FiberRef> * @since 2.0.0 * @category fiberRefs */ -export const currentLogAnnotations: FiberRef> = - core.currentLogAnnotations +export const currentLogAnnotations: FiberRef> = core.currentLogAnnotations /** * @since 2.0.0 @@ -383,7 +382,7 @@ export const currentTracerTimingEnabled: FiberRef = core.currentTracerT * @since 2.0.0 * @category fiberRefs */ -export const currentTracerSpanAnnotations: FiberRef> = +export const currentTracerSpanAnnotations: FiberRef> = core.currentTracerSpanAnnotations /** diff --git a/src/Layer.ts b/src/Layer.ts index c42edf678f..0b3a8422d1 100644 --- a/src/Layer.ts +++ b/src/Layer.ts @@ -845,7 +845,7 @@ export const withSpan: { ( name: string, options?: { - readonly attributes?: Record + readonly attributes?: Record readonly links?: ReadonlyArray readonly parent?: Tracer.ParentSpan readonly root?: boolean @@ -856,7 +856,7 @@ export const withSpan: { self: Layer, name: string, options?: { - readonly attributes?: Record + readonly attributes?: Record readonly links?: ReadonlyArray readonly parent?: Tracer.ParentSpan readonly root?: boolean diff --git a/src/Logger.ts b/src/Logger.ts index 52e96d4ee2..ff69f07929 100644 --- a/src/Logger.ts +++ b/src/Logger.ts @@ -44,7 +44,7 @@ export interface Logger extends Logger.Variance readonly context: FiberRefs.FiberRefs readonly spans: List.List - readonly annotations: HashMap.HashMap + readonly annotations: HashMap.HashMap readonly date: Date } ) => Output @@ -66,12 +66,6 @@ export declare namespace Logger { } } -/** - * @since 2.0.0 - * @category models - */ -export type AnnotationValue = string | number | boolean - /** * @category constructors * @since 2.0.0 @@ -85,7 +79,7 @@ export const make: ( readonly cause: Cause.Cause readonly context: FiberRefs.FiberRefs readonly spans: List.List - readonly annotations: HashMap.HashMap + readonly annotations: HashMap.HashMap readonly date: Date } ) => Output diff --git a/src/Stream.ts b/src/Stream.ts index 0c6f402e84..d8baef1f25 100644 --- a/src/Stream.ts +++ b/src/Stream.ts @@ -4000,7 +4000,7 @@ export const withSpan: { ( name: string, options?: { - readonly attributes?: Record + readonly attributes?: Record readonly links?: ReadonlyArray readonly parent?: Tracer.ParentSpan readonly root?: boolean @@ -4011,7 +4011,7 @@ export const withSpan: { self: Stream, name: string, options?: { - readonly attributes?: Record + readonly attributes?: Record readonly links?: ReadonlyArray readonly parent?: Tracer.ParentSpan readonly root?: boolean diff --git a/src/Tracer.ts b/src/Tracer.ts index 0cef8b14e7..21214e2fa8 100644 --- a/src/Tracer.ts +++ b/src/Tracer.ts @@ -29,6 +29,7 @@ export interface Tracer { parent: Option.Option, context: Context.Context, links: ReadonlyArray, + sampled: boolean, startTime: bigint ) => Span readonly context: (f: () => X, fiber: Fiber.RuntimeFiber) => X @@ -62,6 +63,7 @@ export interface ExternalSpan { readonly _tag: "ExternalSpan" readonly spanId: string readonly traceId: string + readonly sampled: boolean readonly context: Context.Context } @@ -77,17 +79,13 @@ export interface Span { readonly parent: Option.Option readonly context: Context.Context readonly status: SpanStatus - readonly attributes: ReadonlyMap + readonly attributes: ReadonlyMap readonly links: ReadonlyArray + readonly sampled: boolean readonly end: (endTime: bigint, exit: Exit.Exit) => void - readonly attribute: (key: string, value: AttributeValue) => void - readonly event: (name: string, startTime: bigint, attributes?: Record) => void + readonly attribute: (key: string, value: unknown) => void + readonly event: (name: string, startTime: bigint, attributes?: Record) => void } -/** - * @since 2.0.0 - * @category models - */ -export type AttributeValue = string | boolean | number /** * @since 2.0.0 @@ -96,7 +94,7 @@ export type AttributeValue = string | boolean | number export interface SpanLink { readonly _tag: "SpanLink" readonly span: ParentSpan - readonly attributes: Readonly> + readonly attributes: Readonly> } /** @@ -111,6 +109,17 @@ export const Tracer: Context.Tag = internal.tracerTag */ export const make: (options: Omit) => Tracer = internal.make +/** + * @since 2.0.0 + * @category constructors + */ +export const externalSpan: (options: { + readonly spanId: string + readonly traceId: string + readonly sampled?: boolean | undefined + readonly context?: Context.Context | undefined +}) => ExternalSpan = internal.externalSpan + /** * @since 2.0.0 * @category constructors diff --git a/src/internal/channel.ts b/src/internal/channel.ts index cc660b8eb8..5dd949e4ad 100644 --- a/src/internal/channel.ts +++ b/src/internal/channel.ts @@ -2302,7 +2302,7 @@ export const withSpan = dual< ( name: string, options?: { - readonly attributes?: Record + readonly attributes?: Record readonly links?: ReadonlyArray readonly parent?: Tracer.ParentSpan readonly root?: boolean @@ -2315,7 +2315,7 @@ export const withSpan = dual< self: Channel.Channel, name: string, options?: { - readonly attributes?: Record + readonly attributes?: Record readonly links?: ReadonlyArray readonly parent?: Tracer.ParentSpan readonly root?: boolean diff --git a/src/internal/core-effect.ts b/src/internal/core-effect.ts index 0680769c12..d33fe3f947 100644 --- a/src/internal/core-effect.ts +++ b/src/internal/core-effect.ts @@ -22,7 +22,6 @@ import * as metricLabel from "../internal/metric/label" import * as runtimeFlags from "../internal/runtimeFlags" import * as SingleShotGen from "../internal/singleShotGen" import * as List from "../List" -import type * as Logger from "../Logger" import * as LogLevel from "../LogLevel" import * as LogSpan from "../LogSpan" import type * as Metric from "../Metric" @@ -38,14 +37,14 @@ import * as Tracer from "../Tracer" /* @internal */ export const annotateLogs = dual< { - (key: string, value: Logger.AnnotationValue): (effect: Effect.Effect) => Effect.Effect + (key: string, value: unknown): (effect: Effect.Effect) => Effect.Effect ( - values: Record + values: Record ): (effect: Effect.Effect) => Effect.Effect }, { - (effect: Effect.Effect, key: string, value: Logger.AnnotationValue): Effect.Effect - (effect: Effect.Effect, values: Record): Effect.Effect + (effect: Effect.Effect, key: string, value: unknown): Effect.Effect + (effect: Effect.Effect, values: Record): Effect.Effect } >( (args) => core.isEffect(args[0]), @@ -57,7 +56,7 @@ export const annotateLogs = dual< typeof args[1] === "string" ? HashMap.set(args[1], args[2]) : (annotations) => - Object.entries(args[1] as Record).reduce( + Object.entries(args[1] as Record).reduce( (acc, [key, value]) => HashMap.set(acc, key, value), annotations ) @@ -942,7 +941,7 @@ export const withLogSpan = dual< ))) /* @internal */ -export const logAnnotations: Effect.Effect> = core +export const logAnnotations: Effect.Effect> = core .fiberRefGet( core.currentLogAnnotations ) @@ -1897,8 +1896,8 @@ export const serviceMembers = (tag: Context.Tag): { /* @internal */ export const annotateCurrentSpan: { - (key: string, value: Tracer.AttributeValue): Effect.Effect - (values: Record): Effect.Effect + (key: string, value: unknown): Effect.Effect + (values: Record): Effect.Effect } = function(): Effect.Effect { const args = arguments return core.flatMap( @@ -1921,14 +1920,14 @@ export const annotateCurrentSpan: { /* @internal */ export const annotateSpans = dual< { - (key: string, value: Tracer.AttributeValue): (effect: Effect.Effect) => Effect.Effect + (key: string, value: unknown): (effect: Effect.Effect) => Effect.Effect ( - values: Record + values: Record ): (effect: Effect.Effect) => Effect.Effect }, { - (effect: Effect.Effect, key: string, value: Tracer.AttributeValue): Effect.Effect - (effect: Effect.Effect, values: Record): Effect.Effect + (effect: Effect.Effect, key: string, value: unknown): Effect.Effect + (effect: Effect.Effect, values: Record): Effect.Effect } >( (args) => core.isEffect(args[0]), @@ -1940,7 +1939,7 @@ export const annotateSpans = dual< typeof args[1] === "string" ? HashMap.set(args[1], args[2]) : (annotations) => - Object.entries(args[1] as Record).reduce( + Object.entries(args[1] as Record).reduce( (acc, [key, value]) => HashMap.set(acc, key, value), annotations ) @@ -1971,12 +1970,12 @@ export const currentTimeNanosTracing = core.fiberRefGetWith( export const linkSpans = dual< ( span: Tracer.ParentSpan, - attributes?: Record + attributes?: Record ) => (self: Effect.Effect) => Effect.Effect, ( self: Effect.Effect, span: Tracer.ParentSpan, - attributes?: Record + attributes?: Record ) => Effect.Effect >( (args) => core.isEffect(args[0]), @@ -1998,11 +1997,12 @@ export const linkSpans = dual< export const makeSpan = ( name: string, options?: { - readonly attributes?: Record + readonly attributes?: Record readonly links?: ReadonlyArray readonly parent?: Tracer.ParentSpan readonly root?: boolean readonly context?: Context.Context + readonly sampled?: boolean } ) => tracerWith((tracer) => @@ -2031,6 +2031,7 @@ export const makeSpan = ( parent, options?.context ?? Context.empty(), linksArray, + options?.sampled ?? (parent._tag === "Some" ? parent.value.sampled : true), startTime ) HashMap.forEach(annotations, (value, key) => span.attribute(key, value)) @@ -2044,7 +2045,7 @@ export const makeSpan = ( ) /* @internal */ -export const spanAnnotations: Effect.Effect> = core +export const spanAnnotations: Effect.Effect> = core .fiberRefGet(core.currentTracerSpanAnnotations) /* @internal */ @@ -2055,7 +2056,7 @@ export const spanLinks: Effect.Effect export const useSpan: { (name: string, evaluate: (span: Tracer.Span) => Effect.Effect): Effect.Effect (name: string, options: { - readonly attributes?: Record + readonly attributes?: Record readonly links?: ReadonlyArray readonly parent?: Tracer.ParentSpan readonly root?: boolean @@ -2069,7 +2070,7 @@ export const useSpan: { ] ) => { const options: { - readonly attributes?: Record + readonly attributes?: Record readonly links?: ReadonlyArray readonly parent?: Tracer.ParentSpan readonly root?: boolean @@ -2102,14 +2103,14 @@ export const withParentSpan = dual< /** @internal */ export const withSpan = dual< (name: string, options?: { - readonly attributes?: Record + readonly attributes?: Record readonly links?: ReadonlyArray readonly parent?: Tracer.ParentSpan readonly root?: boolean readonly context?: Context.Context }) => (self: Effect.Effect) => Effect.Effect, (self: Effect.Effect, name: string, options?: { - readonly attributes?: Record + readonly attributes?: Record readonly links?: ReadonlyArray readonly parent?: Tracer.ParentSpan readonly root?: boolean diff --git a/src/internal/core.ts b/src/internal/core.ts index 09b61a751e..b84a6fd3e8 100644 --- a/src/internal/core.ts +++ b/src/internal/core.ts @@ -28,7 +28,6 @@ import * as DeferredOpCodes from "../internal/opCodes/deferred" import * as OpCodes from "../internal/opCodes/effect" import * as _runtimeFlags from "../internal/runtimeFlags" import * as List from "../List" -import type * as Logger from "../Logger" import type * as LogLevel from "../LogLevel" import type * as LogSpan from "../LogSpan" import type * as MetricLabel from "../MetricLabel" @@ -1846,7 +1845,7 @@ export const currentMaxOpsBeforeYield: FiberRef.FiberRef = globalValue( ) /** @internal */ -export const currentLogAnnotations: FiberRef.FiberRef> = globalValue( +export const currentLogAnnotations: FiberRef.FiberRef> = globalValue( Symbol.for("effect/FiberRef/currentLogAnnotation"), () => fiberRefUnsafeMake(HashMap.empty()) ) @@ -1945,11 +1944,10 @@ export const currentTracerTimingEnabled: FiberRef.FiberRef = globalValu ) /** @internal */ -export const currentTracerSpanAnnotations: FiberRef.FiberRef> = - globalValue( - Symbol.for("effect/FiberRef/currentTracerSpanAnnotations"), - () => fiberRefUnsafeMake(HashMap.empty()) - ) +export const currentTracerSpanAnnotations: FiberRef.FiberRef> = globalValue( + Symbol.for("effect/FiberRef/currentTracerSpanAnnotations"), + () => fiberRefUnsafeMake(HashMap.empty()) +) /** @internal */ export const currentTracerSpanLinks: FiberRef.FiberRef> = globalValue( diff --git a/src/internal/fiberRuntime.ts b/src/internal/fiberRuntime.ts index 5426fea68c..41acd48cd3 100644 --- a/src/internal/fiberRuntime.ts +++ b/src/internal/fiberRuntime.ts @@ -17,6 +17,7 @@ import * as FiberRefsPatch from "../FiberRefsPatch" import * as FiberStatus from "../FiberStatus" import type { LazyArg } from "../Function" import { dual, identity, pipe } from "../Function" +import * as HashMap from "../HashMap" import * as HashSet from "../HashSet" import * as _RequestBlock from "../internal/blockedRequests" import * as internalCause from "../internal/cause" @@ -1382,7 +1383,7 @@ export const tracerLogger = internalLogger.makeLogger(({ return } - const attributes = Object.fromEntries(annotations) + const attributes = Object.fromEntries(HashMap.map(annotations, (value) => internalLogger.serializeUnknown(value))) attributes["effect.fiberId"] = FiberId.threadName(fiberId) attributes["effect.logLevel"] = logLevel.label @@ -3432,7 +3433,7 @@ export const interruptWhenPossible = dual< export const useSpanScoped = ( name: string, options?: { - readonly attributes?: Record + readonly attributes?: Record readonly links?: ReadonlyArray readonly parent?: Tracer.ParentSpan readonly root?: boolean @@ -3452,7 +3453,7 @@ export const useSpanScoped = ( export const withSpanScoped = ( name: string, options?: { - readonly attributes?: Record + readonly attributes?: Record readonly links?: ReadonlyArray readonly parent?: Tracer.ParentSpan readonly root?: boolean diff --git a/src/internal/layer.ts b/src/internal/layer.ts index a1eb9a1344..645372a9cc 100644 --- a/src/internal/layer.ts +++ b/src/internal/layer.ts @@ -1122,14 +1122,14 @@ export const unwrapScoped = ( /** @internal */ export const withSpan = dual< (name: string, options?: { - readonly attributes?: Record + readonly attributes?: Record readonly links?: ReadonlyArray readonly parent?: Tracer.ParentSpan readonly root?: boolean readonly context?: Context.Context }) => (self: Layer.Layer) => Layer.Layer, (self: Layer.Layer, name: string, options?: { - readonly attributes?: Record + readonly attributes?: Record readonly links?: ReadonlyArray readonly parent?: Tracer.ParentSpan readonly root?: boolean diff --git a/src/internal/layer/circular.ts b/src/internal/layer/circular.ts index de763562c2..bd64556373 100644 --- a/src/internal/layer/circular.ts +++ b/src/internal/layer/circular.ts @@ -190,7 +190,7 @@ export const setParentSpan = (span: Tracer.ParentSpan): Layer.Layer + readonly attributes?: Record readonly links?: ReadonlyArray readonly parent?: Tracer.ParentSpan readonly root?: boolean diff --git a/src/internal/logger.ts b/src/internal/logger.ts index dac5a145f5..199d9df4ec 100644 --- a/src/internal/logger.ts +++ b/src/internal/logger.ts @@ -37,7 +37,7 @@ export const makeLogger = ( readonly cause: CauseExt.Cause readonly context: FiberRefs.FiberRefs readonly spans: List.List - readonly annotations: HashMap.HashMap + readonly annotations: HashMap.HashMap readonly date: Date } ) => Output @@ -207,7 +207,7 @@ export const stringLogger: Logger.Logger = makeLogger( } output = output + filterKeyName(key) output = output + "=" - output = appendQuotedLogfmt(String(value), output) + output = appendQuotedLogfmt(serializeUnknown(value), output) } } diff --git a/src/internal/stream.ts b/src/internal/stream.ts index bbda2ee633..98bed9f321 100644 --- a/src/internal/stream.ts +++ b/src/internal/stream.ts @@ -6843,7 +6843,7 @@ export const withSpan = dual< ( name: string, options?: { - readonly attributes?: Record + readonly attributes?: Record readonly links?: ReadonlyArray readonly parent?: Tracer.ParentSpan readonly root?: boolean @@ -6854,7 +6854,7 @@ export const withSpan = dual< self: Stream.Stream, name: string, options?: { - readonly attributes?: Record + readonly attributes?: Record readonly links?: ReadonlyArray readonly parent?: Tracer.ParentSpan readonly root?: boolean diff --git a/src/internal/tracer.ts b/src/internal/tracer.ts index a572f6c228..f93dc2198f 100644 --- a/src/internal/tracer.ts +++ b/src/internal/tracer.ts @@ -31,14 +31,15 @@ export class NativeSpan implements Tracer.Span { readonly traceId: string = "native" status: Tracer.SpanStatus - attributes: Map - events: Array<[name: string, startTime: bigint, attributes: Record]> = [] + attributes: Map + events: Array<[name: string, startTime: bigint, attributes: Record]> = [] constructor( readonly name: string, readonly parent: Option.Option, readonly context: Context.Context, readonly links: ReadonlyArray, + readonly sampled: boolean, readonly startTime: bigint ) { this.status = { @@ -58,17 +59,39 @@ export class NativeSpan implements Tracer.Span { } } - attribute = (key: string, value: Tracer.AttributeValue): void => { + attribute = (key: string, value: unknown): void => { this.attributes.set(key, value) } - event = (name: string, startTime: bigint, attributes?: Record): void => { + event = (name: string, startTime: bigint, attributes?: Record): void => { this.events.push([name, startTime, attributes ?? {}]) } } /** @internal */ export const nativeTracer: Tracer.Tracer = make({ - span: (name, parent, context, links, startTime) => new NativeSpan(name, parent, context, links, startTime), + span: (name, parent, context, links, sampled, startTime) => + new NativeSpan( + name, + parent, + context, + links, + sampled, + startTime + ), context: (f) => f() }) + +/** @internal */ +export const externalSpan = (options: { + readonly spanId: string + readonly traceId: string + readonly sampled?: boolean + readonly context?: Context.Context +}): Tracer.ExternalSpan => ({ + _tag: "ExternalSpan", + spanId: options.spanId, + traceId: options.traceId, + sampled: options.sampled ?? true, + context: options.context ?? Context.empty() +}) diff --git a/test/Logger.ts b/test/Logger.ts index b84db06d9a..3789324383 100644 --- a/test/Logger.ts +++ b/test/Logger.ts @@ -1,4 +1,5 @@ import * as Cause from "effect/Cause" +import * as Chunk from "effect/Chunk" import * as FiberId from "effect/FiberId" import * as FiberRefs from "effect/FiberRefs" import { identity } from "effect/Function" @@ -24,7 +25,7 @@ describe("stringLogger", () => { const spans = List.make(LogSpan.make("imma span=\"", date.getTime() - 7)) const annotations = HashMap.make( ["just_a_key", "just_a_value"], - ["I am bad key name", JSON.stringify({ coolValue: "cool value" })], + ["I am bad key name", { coolValue: "cool value" }], ["good_key", "I am a good value"], ["good_bool", true], ["good_number", 123] @@ -51,8 +52,8 @@ describe("stringLogger", () => { vi.setSystemTime(date) const spans = List.make(LogSpan.make("imma\nspan=\"", date.getTime() - 7)) const annotations = HashMap.make( - ["I am also\na bad key name", JSON.stringify({ return: "cool\nvalue" })], - ["good_key", JSON.stringify({ returnWithSpace: "cool\nvalue or not" })], + ["I am also\na bad key name", { return: "cool\nvalue" }], + ["good_key", { returnWithSpace: "cool\nvalue or not" }], ["good_key2", "I am a good value\nwith line breaks"], ["good_key3", "I_have=a"] ) @@ -90,7 +91,7 @@ describe("logfmtLogger", () => { const spans = List.make(LogSpan.make("imma span=\"", date.getTime() - 7)) const annotations = HashMap.make( ["just_a_key", "just_a_value"], - ["I am bad key name", JSON.stringify({ coolValue: "cool value" })], + ["I am bad key name", { coolValue: "cool value" }], ["good_key", "I am a good value"] ) @@ -115,8 +116,8 @@ describe("logfmtLogger", () => { vi.setSystemTime(date) const spans = List.make(LogSpan.make("imma\nspan=\"", date.getTime() - 7)) const annotations = HashMap.make( - ["I am also\na bad key name", JSON.stringify({ return: "cool\nvalue" })], - ["good_key", JSON.stringify({ returnWithSpace: "cool\nvalue or not" })], + ["I am also\na bad key name", { return: "cool\nvalue" }], + ["good_key", { returnWithSpace: "cool\nvalue or not" }], ["good_key2", "I am a good value\nwith line breaks"], ["good_key3", "I_have=a"], ["good_bool", true], @@ -226,4 +227,26 @@ describe("logfmtLogger", () => { `timestamp=${date.toJSON()} level=INFO fiber= message="() => \\"hello world\\""` ) }) + + test("annotations", () => { + const date = new Date() + vi.setSystemTime(date) + + const annotations = HashMap.make(["hashmap", HashMap.make(["key", 2])], ["chunk", Chunk.make(1, 2)]) + + const result = Logger.logfmtLogger.log({ + fiberId: FiberId.none, + logLevel: logLevelInfo, + message: "hello world", + cause: Cause.empty, + context: FiberRefs.unsafeMake(new Map()), + spans: List.empty(), + annotations, + date + }) + + expect(result).toEqual( + `timestamp=${date.toJSON()} level=INFO fiber= message="hello world" hashmap="{\\"_id\\":\\"HashMap\\",\\"values\\":[[\\"key\\",2]]}" chunk="{\\"_id\\":\\"Chunk\\",\\"values\\":[1,2]}"` + ) + }) }) diff --git a/test/Tracer.ts b/test/Tracer.ts index 382eddd63b..8b572b2e98 100644 --- a/test/Tracer.ts +++ b/test/Tracer.ts @@ -24,6 +24,7 @@ describe("Tracer", () => { assert.deepEqual(span.name, "A") assert.deepEqual(span.parent, Option.none()) + assert.strictEqual(span.sampled, true) })) it.effect("parent", () => @@ -56,6 +57,7 @@ describe("Tracer", () => { _tag: "ExternalSpan", spanId: "000", traceId: "111", + sampled: true, context: Context.empty() } })(currentSpan) @@ -172,6 +174,7 @@ describe("Tracer", () => { _tag: "ExternalSpan", traceId: "123", spanId: "456", + sampled: true, context: Context.empty() }) ))