@cloudjun/otel-kit 0.2.0 → 0.2.1

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 CHANGED
@@ -1,55 +1,65 @@
1
- # Changelog
2
-
3
- 이 프로젝트는 [Semantic Versioning](https://semver.org/lang/ko/)을 따릅니다.
4
- This project follows [Semantic Versioning](https://semver.org/).
5
-
6
- ## [Unreleased]
7
-
8
- ## [0.2.0] - 2026-09-04
9
-
10
- ### Changed
11
-
12
- - 패키지 이름을 `@cloudjun/otel-kit`으로 변경했습니다. npm 계정 스코프에 맞춘 것으로, GitHub 저장소 주소는 그대로입니다.
13
- - OpenTelemetry SDK를 2.x 계열로 올리고 Node.js 지원 범위를 22 이상으로 조정했습니다.
14
- - 표준 OTEL 환경 변수, 신호별 활성화, 리소스 감지, 샘플러 설정을 지원합니다.
15
- - HTTP 로거의 기본값을 본문·쿼리·클라이언트 IP 비수집으로 변경했습니다.
16
- - 프록시 전달 헤더는 `trustedProxyCount`를 명시한 경우에만 신뢰합니다.
17
- - CI와 npm Trusted Publishing 워크플로를 Node.js 22/24 및 npm 11 기준으로 갱신했습니다.
18
- - `@opentelemetry/api`는 전역 레지스트리 단일 인스턴스를 보장하기 위해 peer dependency로 선언합니다.
19
- - NestJS 진입점이 쓰는 `rxjs`를 optional peer dependency로 명시합니다.
20
- - GitHub Actions를 커밋 SHA로 고정합니다.
21
- - 샘플러·메트릭 주기·프로토콜 검증을 전역 provider 등록 전에 끝내, 잘못된 설정으로 실패해도 절반만 등록된 전역 상태가 남지 않습니다.
22
- - HTTP 로거 크기 제한 옵션을 요청 시점이 아니라 미들웨어 생성 시점에 검증합니다.
23
-
24
- ### Added
25
-
26
- - `@cloudjun/otel-kit/register` 사전 로드 진입점
27
- - `captureError`, `recordErrorOnSpan`, `runWithSpan` 오류·백그라운드 작업 계측 도우미
28
- - NestJS용 `OtelErrorInterceptor`
29
- - 종료와 강제 플러시를 포함한 관측성 핸들 및 실제 활성 신호 정보
30
- - CI: 실제 tarball 을 설치해 진입점을 검증하는 패키지 스모크 테스트(`scripts/smoke-package.sh`), 커버리지 요약·아티팩트, CodeQL 코드 스캔, 태그 푸시 시 GitHub Release 자동 생성
31
- - 초기화된 핸들을 조회하는 `getObservability`. Winston transport 헬퍼가 이를 통해 `enableLogs: false` 같은 옵션까지 반영합니다.
32
-
33
- ### Fixed
34
-
35
- - `OTEL_METRIC_EXPORT_INTERVAL`(또는 `metricExportIntervalMs`)만 30초보다 짧게 설정하면 기본 timeout(30초)이 interval을 초과해 시작 시 `RangeError`가 나던 문제를 수정했습니다. timeout을 명시하지 않으면 interval에 맞춰 자동으로 줄어듭니다.
36
-
37
- ### Docs
38
-
39
- - 로고와 배너(`assets/`), 영어·한국어 README(`README.md`, `README.ko.md`)
40
- - 기여 가이드, 보안 정책(영어·한국어), 이슈·PR 템플릿, Dependabot 설정
41
- - 로컬 OpenTelemetry Collector와 함께 실행하는 `examples/basic` 예제
42
-
43
- ### Security
44
-
45
- - 순환 참조, getter 예외, 과도한 중첩 및 큰 문자열을 방어하는 제한형 로그 직렬화
46
- - 지원하지 않는 OTLP 프로토콜과 잘못된 샘플러·프록시 설정의 조기 실패
47
-
48
- ## [0.1.0] - 2026-09-03
49
-
50
- ### Added
51
-
52
- - 트레이스·로그·메트릭 OTLP/HTTP 부트스트랩
53
- - Winston OpenTelemetry transport
54
- - HTTP 요청 로거, 클라이언트 IP 및 NestJS 실 IP 미들웨어
55
- - 오류 로그 레코드와 trace context 도우미
1
+ # Changelog
2
+
3
+ 이 프로젝트는 [Semantic Versioning](https://semver.org/lang/ko/)을 따릅니다.
4
+ This project follows [Semantic Versioning](https://semver.org/).
5
+
6
+ ## [Unreleased]
7
+
8
+ ## [0.2.1] - 2026-11-23
9
+
10
+ ### Fixed
11
+
12
+ - `moduleResolution`이 `node10`인 프로젝트(`module: commonjs`의 기본값, NestJS 기본 tsconfig)에서 `import ... from '@cloudjun/otel-kit'`가 TS2307로 실패하던 문제를 고쳤습니다. `typesVersions`의 와일드카드(`"*": ["dist/*"]`)가 루트 진입점의 타입 경로(`dist/index.d.ts`)까지 다시 매핑해 `dist/dist/index.d.ts`를 찾고 있었습니다. 와일드카드를 지우고 `nest`와 `register`만 남겼습니다. 런타임 동작은 바뀌지 않습니다.
13
+
14
+ ### Added
15
+
16
+ - CI: 패키지 스모크 테스트가 세 진입점의 타입을 `moduleResolution` `node10`과 `node16` 양쪽에서 검사합니다.
17
+
18
+ ## [0.2.0] - 2026-09-04
19
+
20
+ ### Changed
21
+
22
+ - 패키지 이름을 `@cloudjun/otel-kit`으로 변경했습니다. npm 계정 스코프에 맞춘 것으로, GitHub 저장소 주소는 그대로입니다.
23
+ - OpenTelemetry SDK를 2.x 계열로 올리고 Node.js 지원 범위를 22 이상으로 조정했습니다.
24
+ - 표준 OTEL 환경 변수, 신호별 활성화, 리소스 감지, 샘플러 설정을 지원합니다.
25
+ - HTTP 로거의 기본값을 본문·쿼리·클라이언트 IP 비수집으로 변경했습니다.
26
+ - 프록시 전달 헤더는 `trustedProxyCount`를 명시한 경우에만 신뢰합니다.
27
+ - CI와 npm Trusted Publishing 워크플로를 Node.js 22/24 및 npm 11 기준으로 갱신했습니다.
28
+ - `@opentelemetry/api`는 전역 레지스트리 단일 인스턴스를 보장하기 위해 peer dependency로 선언합니다.
29
+ - NestJS 진입점이 쓰는 `rxjs`를 optional peer dependency로 명시합니다.
30
+ - GitHub Actions를 커밋 SHA로 고정합니다.
31
+ - 샘플러·메트릭 주기·프로토콜 검증을 전역 provider 등록 전에 끝내, 잘못된 설정으로 실패해도 절반만 등록된 전역 상태가 남지 않습니다.
32
+ - HTTP 로거 크기 제한 옵션을 요청 시점이 아니라 미들웨어 생성 시점에 검증합니다.
33
+
34
+ ### Added
35
+
36
+ - `@cloudjun/otel-kit/register` 사전 로드 진입점
37
+ - `captureError`, `recordErrorOnSpan`, `runWithSpan` 오류·백그라운드 작업 계측 도우미
38
+ - NestJS용 `OtelErrorInterceptor`
39
+ - 종료와 강제 플러시를 포함한 관측성 핸들 및 실제 활성 신호 정보
40
+ - CI: 실제 tarball 을 설치해 진입점을 검증하는 패키지 스모크 테스트(`scripts/smoke-package.sh`), 커버리지 요약·아티팩트, CodeQL 코드 스캔, 태그 푸시 시 GitHub Release 자동 생성
41
+ - 초기화된 핸들을 조회하는 `getObservability`. Winston transport 헬퍼가 이를 통해 `enableLogs: false` 같은 옵션까지 반영합니다.
42
+
43
+ ### Fixed
44
+
45
+ - `OTEL_METRIC_EXPORT_INTERVAL`(또는 `metricExportIntervalMs`)만 30초보다 짧게 설정하면 기본 timeout(30초)이 interval을 초과해 시작 시 `RangeError`가 나던 문제를 수정했습니다. timeout을 명시하지 않으면 interval에 맞춰 자동으로 줄어듭니다.
46
+
47
+ ### Docs
48
+
49
+ - 로고와 배너(`assets/`), 영어·한국어 README(`README.md`, `README.ko.md`)
50
+ - 기여 가이드, 보안 정책(영어·한국어), 이슈·PR 템플릿, Dependabot 설정
51
+ - 로컬 OpenTelemetry Collector와 함께 실행하는 `examples/basic` 예제
52
+
53
+ ### Security
54
+
55
+ - 순환 참조, getter 예외, 과도한 중첩 및 큰 문자열을 방어하는 제한형 로그 직렬화
56
+ - 지원하지 않는 OTLP 프로토콜과 잘못된 샘플러·프록시 설정의 조기 실패
57
+
58
+ ## [0.1.0] - 2026-09-03
59
+
60
+ ### Added
61
+
62
+ - 트레이스·로그·메트릭 OTLP/HTTP 부트스트랩
63
+ - Winston OpenTelemetry transport
64
+ - HTTP 요청 로거, 클라이언트 IP 및 NestJS 실 IP 미들웨어
65
+ - 오류 로그 레코드와 trace context 도우미
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,2DAS8B;AAR5B,uHAAA,iBAAiB,OAAA;AACjB,sHAAA,gBAAgB,OAAA;AAChB,yHAAA,mBAAmB,OAAA;AAOrB,iDAAoE;AAA3D,iHAAA,gBAAgB,OAAA;AAAE,gHAAA,eAAe,OAAA;AAC1C,qCAAqC;AAA5B,mGAAA,QAAQ,OAAA;AACjB,+CAAkF;AAAzE,gHAAA,gBAAgB,OAAA;AACzB,qDAI2B;AAHzB,+GAAA,YAAY,OAAA;AACZ,oHAAA,iBAAiB,OAAA;AAGnB,qCAA6D;AAApD,sGAAA,WAAW,OAAA;AACpB,mEAAsE;AAA7D,4HAAA,sBAAsB,OAAA;AAC/B,8CAQ0B;AAPxB,wGAAA,WAAW,OAAA;AACX,wGAAA,WAAW,OAAA;AACX,mHAAA,sBAAsB,OAAA;AAMxB,wEASuC;AARrC,oIAAA,0BAA0B,OAAA;AAC1B,2HAAA,iBAAiB,OAAA;AACjB,gIAAA,sBAAsB,OAAA;AAQxB,gEAAgE;AAChE,0CAA8D;AAArD,+FAAA,QAAQ,OAAA;AAAE,qGAAA,cAAc,OAAA","sourcesContent":["/**\r\n * @cloudjun/otel-kit — 프레임워크 무관 진입점.\r\n * NestJS 전용 미들웨어는 `@cloudjun/otel-kit/nest` 에서 import 한다.\r\n */\r\nexport {\r\n initObservability,\r\n getObservability,\r\n isOtelExportEnabled,\r\n IInitObservabilityOptions,\r\n IObservabilityHandle,\r\n IObservabilitySignals,\r\n OtelSignal,\r\n ResourceAttributeValue,\r\n} from './init-observability';\r\nexport { getActiveTraceId, getActiveSpanId } from './trace-context';\r\nexport { getMeter } from './metrics';\r\nexport { toErrorLogRecord, IErrorLogMeta, IErrorLogRecord } from './error-record';\r\nexport {\r\n captureError,\r\n recordErrorOnSpan,\r\n IRecordErrorOnSpanOptions,\r\n} from './error-telemetry';\r\nexport { runWithSpan, IRunWithSpanOptions } from './tracing';\r\nexport { createOtelLogTransport } from './winston/otel-log-transport';\r\nexport {\r\n extractIPv4,\r\n getClientIp,\r\n createRealIpMiddleware,\r\n IClientIpRequest,\r\n IRealIpRequest,\r\n IRealIpOptions,\r\n RealIpMiddlewareFn,\r\n} from './http/client-ip';\r\nexport {\r\n createHttpLoggerMiddleware,\r\n maskSensitiveData,\r\n DEFAULT_SENSITIVE_KEYS,\r\n IHttpLoggerOptions,\r\n IHttpLogWriter,\r\n IHttpLoggerRequest,\r\n IHttpLoggerResponse,\r\n HttpLoggerMiddlewareFn,\r\n} from './http/http-logger.middleware';\r\n\r\n// 소비 프로젝트가 @opentelemetry/api 를 직접 설치하지 않아도 타입을 쓸 수 있도록 재export\r\nexport { SpanKind, SpanStatusCode } from '@opentelemetry/api';\r\nexport type { Meter, Attributes, Span, ObservableResult } from '@opentelemetry/api';\r\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,2DAS8B;AAR5B,uHAAA,iBAAiB,OAAA;AACjB,sHAAA,gBAAgB,OAAA;AAChB,yHAAA,mBAAmB,OAAA;AAOrB,iDAAoE;AAA3D,iHAAA,gBAAgB,OAAA;AAAE,gHAAA,eAAe,OAAA;AAC1C,qCAAqC;AAA5B,mGAAA,QAAQ,OAAA;AACjB,+CAAkF;AAAzE,gHAAA,gBAAgB,OAAA;AACzB,qDAI2B;AAHzB,+GAAA,YAAY,OAAA;AACZ,oHAAA,iBAAiB,OAAA;AAGnB,qCAA6D;AAApD,sGAAA,WAAW,OAAA;AACpB,mEAAsE;AAA7D,4HAAA,sBAAsB,OAAA;AAC/B,8CAQ0B;AAPxB,wGAAA,WAAW,OAAA;AACX,wGAAA,WAAW,OAAA;AACX,mHAAA,sBAAsB,OAAA;AAMxB,wEASuC;AARrC,oIAAA,0BAA0B,OAAA;AAC1B,2HAAA,iBAAiB,OAAA;AACjB,gIAAA,sBAAsB,OAAA;AAQxB,gEAAgE;AAChE,0CAA8D;AAArD,+FAAA,QAAQ,OAAA;AAAE,qGAAA,cAAc,OAAA","sourcesContent":["/**\n * @cloudjun/otel-kit — 프레임워크 무관 진입점.\n * NestJS 전용 미들웨어는 `@cloudjun/otel-kit/nest` 에서 import 한다.\n */\nexport {\n initObservability,\n getObservability,\n isOtelExportEnabled,\n IInitObservabilityOptions,\n IObservabilityHandle,\n IObservabilitySignals,\n OtelSignal,\n ResourceAttributeValue,\n} from './init-observability';\nexport { getActiveTraceId, getActiveSpanId } from './trace-context';\nexport { getMeter } from './metrics';\nexport { toErrorLogRecord, IErrorLogMeta, IErrorLogRecord } from './error-record';\nexport {\n captureError,\n recordErrorOnSpan,\n IRecordErrorOnSpanOptions,\n} from './error-telemetry';\nexport { runWithSpan, IRunWithSpanOptions } from './tracing';\nexport { createOtelLogTransport } from './winston/otel-log-transport';\nexport {\n extractIPv4,\n getClientIp,\n createRealIpMiddleware,\n IClientIpRequest,\n IRealIpRequest,\n IRealIpOptions,\n RealIpMiddlewareFn,\n} from './http/client-ip';\nexport {\n createHttpLoggerMiddleware,\n maskSensitiveData,\n DEFAULT_SENSITIVE_KEYS,\n IHttpLoggerOptions,\n IHttpLogWriter,\n IHttpLoggerRequest,\n IHttpLoggerResponse,\n HttpLoggerMiddlewareFn,\n} from './http/http-logger.middleware';\n\n// 소비 프로젝트가 @opentelemetry/api 를 직접 설치하지 않아도 타입을 쓸 수 있도록 재export\nexport { SpanKind, SpanStatusCode } from '@opentelemetry/api';\nexport type { Meter, Attributes, Span, ObservableResult } from '@opentelemetry/api';\n"]}
package/dist/nest.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"nest.js","sourceRoot":"","sources":["../src/nest.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,gEAA8E;AAArE,sHAAA,gBAAgB,OAAA;AAAE,qHAAA,eAAe,OAAA;AAC1C,wEAIuC;AAHrC,8HAAA,oBAAoB,OAAA;AACpB,wIAAA,8BAA8B,OAAA","sourcesContent":["/**\r\n * @cloudjun/otel-kit/nest — NestJS 전용 진입점.\r\n * `@nestjs/common` 이 설치된 프로젝트에서만 import 한다.\r\n */\r\nexport { RealIpMiddleware, REAL_IP_OPTIONS } from './nest/real-ip.middleware';\r\nexport {\r\n OtelErrorInterceptor,\r\n OTEL_ERROR_INTERCEPTOR_OPTIONS,\r\n IOtelErrorInterceptorOptions,\r\n} from './nest/otel-error.interceptor';\r\n"]}
1
+ {"version":3,"file":"nest.js","sourceRoot":"","sources":["../src/nest.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,gEAA8E;AAArE,sHAAA,gBAAgB,OAAA;AAAE,qHAAA,eAAe,OAAA;AAC1C,wEAIuC;AAHrC,8HAAA,oBAAoB,OAAA;AACpB,wIAAA,8BAA8B,OAAA","sourcesContent":["/**\n * @cloudjun/otel-kit/nest — NestJS 전용 진입점.\n * `@nestjs/common` 이 설치된 프로젝트에서만 import 한다.\n */\nexport { RealIpMiddleware, REAL_IP_OPTIONS } from './nest/real-ip.middleware';\nexport {\n OtelErrorInterceptor,\n OTEL_ERROR_INTERCEPTOR_OPTIONS,\n IOtelErrorInterceptorOptions,\n} from './nest/otel-error.interceptor';\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"register.js","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":";;;AAAA;;;;;;;GAOG;AACH,6DAAyD;AAEzD,uEAAuE;AAC1D,QAAA,aAAa,GAAG,IAAA,sCAAiB,GAAE,CAAC","sourcesContent":["/**\r\n * 환경변수 기반 preload 진입점.\r\n *\r\n * 애플리케이션 모듈보다 먼저 `node --require @cloudjun/otel-kit/register` 로 로드한다.\r\n * 옵션 없이 `initObservability()` 를 호출하므로 서비스 이름 · endpoint · sampler 는 모두\r\n * OTEL_* 환경변수로 지정한다. 프로그램에서 옵션을 넘겨야 한다면 이 진입점 대신\r\n * `initObservability` 를 직접 호출한다 (둘 중 하나만 쓴다).\r\n */\r\nimport { initObservability } from './init-observability';\r\n\r\n/** preload 시 생성된 관측성 핸들. 종료 흐름에서 `shutdown()` 을 await 할 때 import 한다 */\r\nexport const observability = initObservability();\r\n"]}
1
+ {"version":3,"file":"register.js","sourceRoot":"","sources":["../src/register.ts"],"names":[],"mappings":";;;AAAA;;;;;;;GAOG;AACH,6DAAyD;AAEzD,uEAAuE;AAC1D,QAAA,aAAa,GAAG,IAAA,sCAAiB,GAAE,CAAC","sourcesContent":["/**\n * 환경변수 기반 preload 진입점.\n *\n * 애플리케이션 모듈보다 먼저 `node --require @cloudjun/otel-kit/register` 로 로드한다.\n * 옵션 없이 `initObservability()` 를 호출하므로 서비스 이름 · endpoint · sampler 는 모두\n * OTEL_* 환경변수로 지정한다. 프로그램에서 옵션을 넘겨야 한다면 이 진입점 대신\n * `initObservability` 를 직접 호출한다 (둘 중 하나만 쓴다).\n */\nimport { initObservability } from './init-observability';\n\n/** preload 시 생성된 관측성 핸들. 종료 흐름에서 `shutdown()` 을 await 할 때 import 한다 */\nexport const observability = initObservability();\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"tracing.js","sourceRoot":"","sources":["../src/tracing.ts"],"names":[],"mappings":";;AAiDA,kCAyBC;AA1ED;;;;;;GAMG;AACH,4CAAuE;AACvE,uDAAsD;AAmBtD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACI,KAAK,UAAU,WAAW,CAC/B,IAAY,EACZ,SAAyC,EACzC,UAA+B,EAAE;IAEjC,MAAM,MAAM,GAAG,WAAK,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,IAAI,oBAAoB,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;IAC5F,OAAO,MAAM,CAAC,eAAe,CAC3B,IAAI,EACJ;QACE,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,cAAQ,CAAC,QAAQ;QACvC,UAAU,EAAE,OAAO,CAAC,UAAU;KAC/B,EACD,KAAK,EAAC,IAAI,EAAC,EAAE;QACX,IAAI,CAAC;YACH,OAAO,MAAM,SAAS,CAAC,IAAI,CAAC,CAAC;QAC/B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,SAAS,GACb,OAAO,OAAO,CAAC,SAAS,KAAK,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC;YACzF,IAAA,mCAAiB,EAAC,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;YAC9C,MAAM,KAAK,CAAC;QACd,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,GAAG,EAAE,CAAC;QACb,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC","sourcesContent":["/**\r\n * HTTP 요청 밖의 폴링 · 큐 소비 · 배치 작업을 활성 span 으로 감싸는 헬퍼.\r\n *\r\n * HttpInstrumentation 은 들어오는 HTTP 요청에만 span 을 만들기 때문에, 스케줄러나\r\n * 메시지 consumer 처럼 요청이 없는 작업은 `runWithSpan` 으로 직접 경계를 만들어야\r\n * 트레이스에 나타나고 오류가 span 에 기록된다.\r\n */\r\nimport { Attributes, Span, SpanKind, trace } from '@opentelemetry/api';\r\nimport { recordErrorOnSpan } from './error-telemetry';\r\n\r\n/**\r\n * `runWithSpan` 옵션.\r\n *\r\n * @property scope tracer 의 instrumentation scope 이름. 기본값은 이 패키지 이름\r\n * @property scopeVersion instrumentation scope 버전 (선택)\r\n * @property kind span 종류. 폴링·배치는 INTERNAL(기본), 큐 consumer 는 CONSUMER, 외부 전송은 PRODUCER 를 권장\r\n * @property attributes span 시작 시 부착할 속성. 저카디널리티 값 위주로 넣는다\r\n * @property errorType 오류 발생 시 `error.type` 속성으로 기록할 저카디널리티 코드. 함수를 주면 오류별로 분류할 수 있다\r\n */\r\nexport interface IRunWithSpanOptions {\r\n scope?: string;\r\n scopeVersion?: string;\r\n kind?: SpanKind;\r\n attributes?: Attributes;\r\n errorType?: string | ((error: unknown) => string | undefined);\r\n}\r\n\r\n/**\r\n * 작업을 새 활성 span 안에서 실행한다.\r\n *\r\n * - 작업이 던진 오류는 `recordErrorOnSpan` 으로 span 에 exception 과 ERROR 상태를 기록한 뒤\r\n * **원래 값 그대로** 다시 throw 된다. 호출자의 오류 처리 흐름은 바뀌지 않는다.\r\n * - 동기 throw 와 비동기 reject 를 모두 같은 방식으로 처리한다.\r\n * - 성공 · 실패와 관계없이 span 은 항상 종료된다.\r\n *\r\n * @typeParam T 작업의 반환 타입\r\n * @param name span 이름. `chzzk.channel.poll` 처럼 `<도메인>.<대상>.<동작>` 형식을 권장한다\r\n * @param operation 실행할 작업. 인자로 받은 span 에 속성이나 이벤트를 추가할 수 있다\r\n * @param options span 종류 · 속성 · 오류 분류 코드\r\n * @returns 작업의 반환값\r\n * @throws 작업이 던진 오류를 그대로 다시 던진다\r\n *\r\n * @example\r\n * await runWithSpan('chzzk.channel.poll', () => tracker.poll(channelId), {\r\n * kind: SpanKind.INTERNAL,\r\n * attributes: { 'chzzk.channel.id': channelId },\r\n * errorType: 'CHZZK_CHANNEL_POLL_FAILED',\r\n * });\r\n */\r\nexport async function runWithSpan<T>(\r\n name: string,\r\n operation: (span: Span) => T | Promise<T>,\r\n options: IRunWithSpanOptions = {},\r\n): Promise<T> {\r\n const tracer = trace.getTracer(options.scope ?? '@cloudjun/otel-kit', options.scopeVersion);\r\n return tracer.startActiveSpan(\r\n name,\r\n {\r\n kind: options.kind ?? SpanKind.INTERNAL,\r\n attributes: options.attributes,\r\n },\r\n async span => {\r\n try {\r\n return await operation(span);\r\n } catch (error) {\r\n const errorType =\r\n typeof options.errorType === 'function' ? options.errorType(error) : options.errorType;\r\n recordErrorOnSpan(error, { span, errorType });\r\n throw error;\r\n } finally {\r\n span.end();\r\n }\r\n },\r\n );\r\n}\r\n"]}
1
+ {"version":3,"file":"tracing.js","sourceRoot":"","sources":["../src/tracing.ts"],"names":[],"mappings":";;AAiDA,kCAyBC;AA1ED;;;;;;GAMG;AACH,4CAAuE;AACvE,uDAAsD;AAmBtD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACI,KAAK,UAAU,WAAW,CAC/B,IAAY,EACZ,SAAyC,EACzC,UAA+B,EAAE;IAEjC,MAAM,MAAM,GAAG,WAAK,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK,IAAI,oBAAoB,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;IAC5F,OAAO,MAAM,CAAC,eAAe,CAC3B,IAAI,EACJ;QACE,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,cAAQ,CAAC,QAAQ;QACvC,UAAU,EAAE,OAAO,CAAC,UAAU;KAC/B,EACD,KAAK,EAAC,IAAI,EAAC,EAAE;QACX,IAAI,CAAC;YACH,OAAO,MAAM,SAAS,CAAC,IAAI,CAAC,CAAC;QAC/B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,SAAS,GACb,OAAO,OAAO,CAAC,SAAS,KAAK,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC;YACzF,IAAA,mCAAiB,EAAC,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;YAC9C,MAAM,KAAK,CAAC;QACd,CAAC;gBAAS,CAAC;YACT,IAAI,CAAC,GAAG,EAAE,CAAC;QACb,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC","sourcesContent":["/**\n * HTTP 요청 밖의 폴링 · 큐 소비 · 배치 작업을 활성 span 으로 감싸는 헬퍼.\n *\n * HttpInstrumentation 은 들어오는 HTTP 요청에만 span 을 만들기 때문에, 스케줄러나\n * 메시지 consumer 처럼 요청이 없는 작업은 `runWithSpan` 으로 직접 경계를 만들어야\n * 트레이스에 나타나고 오류가 span 에 기록된다.\n */\nimport { Attributes, Span, SpanKind, trace } from '@opentelemetry/api';\nimport { recordErrorOnSpan } from './error-telemetry';\n\n/**\n * `runWithSpan` 옵션.\n *\n * @property scope tracer 의 instrumentation scope 이름. 기본값은 이 패키지 이름\n * @property scopeVersion instrumentation scope 버전 (선택)\n * @property kind span 종류. 폴링·배치는 INTERNAL(기본), 큐 consumer 는 CONSUMER, 외부 전송은 PRODUCER 를 권장\n * @property attributes span 시작 시 부착할 속성. 저카디널리티 값 위주로 넣는다\n * @property errorType 오류 발생 시 `error.type` 속성으로 기록할 저카디널리티 코드. 함수를 주면 오류별로 분류할 수 있다\n */\nexport interface IRunWithSpanOptions {\n scope?: string;\n scopeVersion?: string;\n kind?: SpanKind;\n attributes?: Attributes;\n errorType?: string | ((error: unknown) => string | undefined);\n}\n\n/**\n * 작업을 새 활성 span 안에서 실행한다.\n *\n * - 작업이 던진 오류는 `recordErrorOnSpan` 으로 span 에 exception 과 ERROR 상태를 기록한 뒤\n * **원래 값 그대로** 다시 throw 된다. 호출자의 오류 처리 흐름은 바뀌지 않는다.\n * - 동기 throw 와 비동기 reject 를 모두 같은 방식으로 처리한다.\n * - 성공 · 실패와 관계없이 span 은 항상 종료된다.\n *\n * @typeParam T 작업의 반환 타입\n * @param name span 이름. `chzzk.channel.poll` 처럼 `<도메인>.<대상>.<동작>` 형식을 권장한다\n * @param operation 실행할 작업. 인자로 받은 span 에 속성이나 이벤트를 추가할 수 있다\n * @param options span 종류 · 속성 · 오류 분류 코드\n * @returns 작업의 반환값\n * @throws 작업이 던진 오류를 그대로 다시 던진다\n *\n * @example\n * await runWithSpan('chzzk.channel.poll', () => tracker.poll(channelId), {\n * kind: SpanKind.INTERNAL,\n * attributes: { 'chzzk.channel.id': channelId },\n * errorType: 'CHZZK_CHANNEL_POLL_FAILED',\n * });\n */\nexport async function runWithSpan<T>(\n name: string,\n operation: (span: Span) => T | Promise<T>,\n options: IRunWithSpanOptions = {},\n): Promise<T> {\n const tracer = trace.getTracer(options.scope ?? '@cloudjun/otel-kit', options.scopeVersion);\n return tracer.startActiveSpan(\n name,\n {\n kind: options.kind ?? SpanKind.INTERNAL,\n attributes: options.attributes,\n },\n async span => {\n try {\n return await operation(span);\n } catch (error) {\n const errorType =\n typeof options.errorType === 'function' ? options.errorType(error) : options.errorType;\n recordErrorOnSpan(error, { span, errorType });\n throw error;\n } finally {\n span.end();\n }\n },\n );\n}\n"]}
package/package.json CHANGED
@@ -1,125 +1,122 @@
1
- {
2
- "name": "@cloudjun/otel-kit",
3
- "version": "0.2.0",
4
- "description": "Zero-config OpenTelemetry bootstrap for Node.js services: traces, logs (winston), metrics over OTLP/HTTP. Works with SigNoz, Grafana, or any OTLP backend. Optional NestJS middlewares.",
5
- "keywords": [
6
- "opentelemetry",
7
- "otel",
8
- "otlp",
9
- "signoz",
10
- "winston",
11
- "nestjs",
12
- "observability",
13
- "tracing",
14
- "logging",
15
- "metrics"
16
- ],
17
- "main": "dist/index.js",
18
- "types": "dist/index.d.ts",
19
- "exports": {
20
- ".": {
21
- "types": "./dist/index.d.ts",
22
- "default": "./dist/index.js"
23
- },
24
- "./nest": {
25
- "types": "./dist/nest.d.ts",
26
- "default": "./dist/nest.js"
27
- },
28
- "./register": {
29
- "types": "./dist/register.d.ts",
30
- "default": "./dist/register.js"
31
- },
32
- "./package.json": "./package.json"
33
- },
34
- "sideEffects": [
35
- "./dist/register.js"
36
- ],
37
- "typesVersions": {
38
- "*": {
39
- "nest": [
40
- "dist/nest.d.ts"
41
- ],
42
- "register": [
43
- "dist/register.d.ts"
44
- ],
45
- "*": [
46
- "dist/*"
47
- ]
48
- }
49
- },
50
- "files": [
51
- "dist",
52
- "README.md",
53
- "LICENSE",
54
- "CHANGELOG.md"
55
- ],
56
- "engines": {
57
- "node": ">=22"
58
- },
59
- "packageManager": "npm@11.9.0",
60
- "scripts": {
61
- "build": "tsc -p tsconfig.build.json",
62
- "test": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js",
63
- "test:cov": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js --coverage",
64
- "test:ci": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js --coverage --runInBand",
65
- "typecheck": "tsc -p tsconfig.json --noEmit",
66
- "prepack": "npm run build",
67
- "prepublishOnly": "npm run typecheck && npm run test:ci"
68
- },
69
- "repository": {
70
- "type": "git",
71
- "url": "git+https://github.com/sistinafibel/otel-kit.git"
72
- },
73
- "homepage": "https://github.com/sistinafibel/otel-kit#readme",
74
- "bugs": {
75
- "url": "https://github.com/sistinafibel/otel-kit/issues"
76
- },
77
- "author": "sistinafibel",
78
- "license": "MIT",
79
- "publishConfig": {
80
- "access": "public"
81
- },
82
- "dependencies": {
83
- "@opentelemetry/api-logs": "0.222.0",
84
- "@opentelemetry/exporter-logs-otlp-http": "0.222.0",
85
- "@opentelemetry/exporter-metrics-otlp-http": "0.222.0",
86
- "@opentelemetry/exporter-trace-otlp-http": "0.222.0",
87
- "@opentelemetry/instrumentation": "0.222.0",
88
- "@opentelemetry/instrumentation-http": "0.222.0",
89
- "@opentelemetry/resources": "2.11.0",
90
- "@opentelemetry/sdk-logs": "0.222.0",
91
- "@opentelemetry/sdk-metrics": "2.11.0",
92
- "@opentelemetry/sdk-trace-base": "2.11.0",
93
- "@opentelemetry/sdk-trace-node": "2.11.0",
94
- "@opentelemetry/semantic-conventions": "1.43.0",
95
- "@opentelemetry/winston-transport": "0.32.0"
96
- },
97
- "peerDependencies": {
98
- "@nestjs/common": ">=10 <13",
99
- "@opentelemetry/api": "^1.9.0",
100
- "rxjs": ">=7.1 <8",
101
- "winston": ">=3 <4"
102
- },
103
- "peerDependenciesMeta": {
104
- "@nestjs/common": {
105
- "optional": true
106
- },
107
- "rxjs": {
108
- "optional": true
109
- },
110
- "winston": {
111
- "optional": true
112
- }
113
- },
114
- "devDependencies": {
115
- "@nestjs/common": "^11.0.0",
116
- "@opentelemetry/api": "1.9.1",
117
- "@types/jest": "^29.5.14",
118
- "@types/node": "^22.0.0",
119
- "jest": "^29.7.0",
120
- "rxjs": "^7.8.0",
121
- "ts-jest": "^29.2.5",
122
- "typescript": "^5.7.0",
123
- "winston": "^3.13.0"
124
- }
125
- }
1
+ {
2
+ "name": "@cloudjun/otel-kit",
3
+ "version": "0.2.1",
4
+ "description": "Zero-config OpenTelemetry bootstrap for Node.js services: traces, logs (winston), metrics over OTLP/HTTP. Works with SigNoz, Grafana, or any OTLP backend. Optional NestJS middlewares.",
5
+ "keywords": [
6
+ "opentelemetry",
7
+ "otel",
8
+ "otlp",
9
+ "signoz",
10
+ "winston",
11
+ "nestjs",
12
+ "observability",
13
+ "tracing",
14
+ "logging",
15
+ "metrics"
16
+ ],
17
+ "main": "dist/index.js",
18
+ "types": "dist/index.d.ts",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "default": "./dist/index.js"
23
+ },
24
+ "./nest": {
25
+ "types": "./dist/nest.d.ts",
26
+ "default": "./dist/nest.js"
27
+ },
28
+ "./register": {
29
+ "types": "./dist/register.d.ts",
30
+ "default": "./dist/register.js"
31
+ },
32
+ "./package.json": "./package.json"
33
+ },
34
+ "sideEffects": [
35
+ "./dist/register.js"
36
+ ],
37
+ "typesVersions": {
38
+ "*": {
39
+ "nest": [
40
+ "dist/nest.d.ts"
41
+ ],
42
+ "register": [
43
+ "dist/register.d.ts"
44
+ ]
45
+ }
46
+ },
47
+ "files": [
48
+ "dist",
49
+ "README.md",
50
+ "LICENSE",
51
+ "CHANGELOG.md"
52
+ ],
53
+ "engines": {
54
+ "node": ">=22"
55
+ },
56
+ "packageManager": "npm@11.9.0",
57
+ "scripts": {
58
+ "build": "tsc -p tsconfig.build.json",
59
+ "test": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js",
60
+ "test:cov": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js --coverage",
61
+ "test:ci": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js --coverage --runInBand",
62
+ "typecheck": "tsc -p tsconfig.json --noEmit",
63
+ "prepack": "npm run build",
64
+ "prepublishOnly": "npm run typecheck && npm run test:ci"
65
+ },
66
+ "repository": {
67
+ "type": "git",
68
+ "url": "git+https://github.com/sistinafibel/otel-kit.git"
69
+ },
70
+ "homepage": "https://github.com/sistinafibel/otel-kit#readme",
71
+ "bugs": {
72
+ "url": "https://github.com/sistinafibel/otel-kit/issues"
73
+ },
74
+ "author": "sistinafibel",
75
+ "license": "MIT",
76
+ "publishConfig": {
77
+ "access": "public"
78
+ },
79
+ "dependencies": {
80
+ "@opentelemetry/api-logs": "0.222.0",
81
+ "@opentelemetry/exporter-logs-otlp-http": "0.222.0",
82
+ "@opentelemetry/exporter-metrics-otlp-http": "0.222.0",
83
+ "@opentelemetry/exporter-trace-otlp-http": "0.222.0",
84
+ "@opentelemetry/instrumentation": "0.222.0",
85
+ "@opentelemetry/instrumentation-http": "0.222.0",
86
+ "@opentelemetry/resources": "2.11.0",
87
+ "@opentelemetry/sdk-logs": "0.222.0",
88
+ "@opentelemetry/sdk-metrics": "2.11.0",
89
+ "@opentelemetry/sdk-trace-base": "2.11.0",
90
+ "@opentelemetry/sdk-trace-node": "2.11.0",
91
+ "@opentelemetry/semantic-conventions": "1.43.0",
92
+ "@opentelemetry/winston-transport": "0.32.0"
93
+ },
94
+ "peerDependencies": {
95
+ "@nestjs/common": ">=10 <13",
96
+ "@opentelemetry/api": "^1.9.0",
97
+ "rxjs": ">=7.1 <8",
98
+ "winston": ">=3 <4"
99
+ },
100
+ "peerDependenciesMeta": {
101
+ "@nestjs/common": {
102
+ "optional": true
103
+ },
104
+ "rxjs": {
105
+ "optional": true
106
+ },
107
+ "winston": {
108
+ "optional": true
109
+ }
110
+ },
111
+ "devDependencies": {
112
+ "@nestjs/common": "^11.0.0",
113
+ "@opentelemetry/api": "1.9.1",
114
+ "@types/jest": "^29.5.14",
115
+ "@types/node": "^22.0.0",
116
+ "jest": "^29.7.0",
117
+ "rxjs": "^7.8.0",
118
+ "ts-jest": "^29.2.5",
119
+ "typescript": "^5.7.0",
120
+ "winston": "^3.13.0"
121
+ }
122
+ }