@launchdarkly/node-server-sdk-otel 0.0.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/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright 2022 Catamorphic, Co.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,79 @@
1
+ # LaunchDarkly Server-Side SDK for Node.js - OpenTelemetry integration
2
+
3
+ [![NPM][node-otel-npm-badge]][node-otel-npm-link]
4
+ [![Actions Status][node-otel-ci-badge]][node-otel-ci]
5
+ [![Documentation](https://img.shields.io/static/v1?label=GitHub+Pages&message=API+reference&color=00add8)](https://launchdarkly.github.io/js-core/packages/telemetry/node-server-sdk-otel/docs/)
6
+
7
+ # 🚫🚫🚫🚫🚫🚫
8
+
9
+ > [!CAUTION]
10
+ > This package is prerelease and experimental. It should not be used in production and is not supported.
11
+
12
+ This package provides OpenTelemetry integrations for the LaunchDarkly Server-Side SDK for Node.js.
13
+
14
+ ## LaunchDarkly overview
15
+
16
+ [LaunchDarkly](https://www.launchdarkly.com) is a feature management platform that serves over 100 billion feature flags daily to help teams build better software, faster. [Get started](https://docs.launchdarkly.com/home/getting-started) using LaunchDarkly today!
17
+
18
+ [![Twitter Follow](https://img.shields.io/twitter/follow/launchdarkly.svg?style=social&label=Follow&maxAge=2592000)](https://twitter.com/intent/follow?screen_name=launchdarkly)
19
+
20
+ ## Supported Node versions
21
+
22
+ This package is compatible with Node.js versions 14 and above.
23
+
24
+ ## Getting started
25
+
26
+ Refer to [Using Redis as a persistent feature store](https://docs.launchdarkly.com/sdk/features/storing-data/otel#nodejs-server-side).
27
+
28
+ ## Quick setup
29
+
30
+ This assumes that you have already installed the LaunchDarkly Node.js SDK.
31
+
32
+ 1. Install this package with `npm` or `yarn`:
33
+
34
+ ```shell
35
+ npm install @launchdarkly/node-server-sdk-otel --save
36
+ ```
37
+
38
+ 2. If your application does not already have its own dependency on the `@opentelemetry/api` package, add `@opentelemetry/api` as well:
39
+
40
+ ```shell
41
+ npm install @opentelemetry/api --save
42
+ ```
43
+
44
+ 3. Import the tracing hook:
45
+
46
+ ```typescript
47
+ import { TracingHook } from '@launchdarkly/node-server-sdk-otel';
48
+ ```
49
+
50
+ 4. When configuring your SDK client, add the `TracingHook`
51
+
52
+ ```typescript
53
+ import { init } from '@launchdarkly/node-server-sdk';
54
+
55
+ const client = init('YOUR SDK KEY', {hooks: [new TracingHook()]});
56
+ ```
57
+
58
+ ## Contributing
59
+
60
+ We encourage pull requests and other contributions from the community. Check out our [contributing guidelines](CONTRIBUTING.md) for instructions on how to contribute to this SDK.
61
+
62
+ ## About LaunchDarkly
63
+
64
+ - LaunchDarkly is a continuous delivery platform that provides feature flags as a service and allows developers to iterate quickly and safely. We allow you to easily flag your features and manage them from the LaunchDarkly dashboard. With LaunchDarkly, you can:
65
+ - Roll out a new feature to a subset of your users (like a group of users who opt-in to a beta tester group), gathering feedback and bug reports from real-world use cases.
66
+ - Gradually roll out a feature to an increasing percentage of users, and track the effect that the feature has on key metrics (for instance, how likely is a user to complete a purchase if they have feature A versus feature B?).
67
+ - Turn off a feature that you realize is causing performance problems in production, without needing to re-deploy, or even restart the application with a changed configuration file.
68
+ - Grant access to certain features based on user attributes, like payment plan (eg: users on the ‘gold’ plan get access to more features than users in the ‘silver’ plan). Disable parts of your application to facilitate maintenance, without taking everything offline.
69
+ - LaunchDarkly provides feature flag SDKs for a wide variety of languages and technologies. Check out [our documentation](https://docs.launchdarkly.com/sdk) for a complete list.
70
+ - Explore LaunchDarkly
71
+ - [launchdarkly.com](https://www.launchdarkly.com/ 'LaunchDarkly Main Website') for more information
72
+ - [docs.launchdarkly.com](https://docs.launchdarkly.com/ 'LaunchDarkly Documentation') for our documentation and SDK reference guides
73
+ - [apidocs.launchdarkly.com](https://apidocs.launchdarkly.com/ 'LaunchDarkly API Documentation') for our API documentation
74
+ - [blog.launchdarkly.com](https://blog.launchdarkly.com/ 'LaunchDarkly Blog Documentation') for the latest product updates
75
+
76
+ [node-otel-ci-badge]: https://github.com/launchdarkly/js-core/actions/workflows/node-otel.yml/badge.svg
77
+ [node-otel-ci]: https://github.com/launchdarkly/js-core/actions/workflows/node-otel.yml
78
+ [node-otel-npm-badge]: https://img.shields.io/npm/v/@launchdarkly/node-server-sdk-otel.svg?style=flat-square
79
+ [node-otel-npm-link]: https://www.npmjs.com/package/@launchdarkly/node-server-sdk-otel
@@ -0,0 +1,22 @@
1
+ import { integrations, LDEvaluationDetail } from '@launchdarkly/node-server-sdk';
2
+ /**
3
+ * Options which allow configuring the tracing hook.
4
+ */
5
+ export interface TracingHookOptions {
6
+ /**
7
+ * If set to true, then the tracing hook will add spans for each variation
8
+ * method call.
9
+ *
10
+ * The default value is false.
11
+ */
12
+ spans: boolean;
13
+ }
14
+ export default class TracingHook implements integrations.Hook {
15
+ private readonly options;
16
+ private readonly tracer;
17
+ constructor(options?: TracingHookOptions);
18
+ getMetadata(): integrations.HookMetadata;
19
+ beforeEvaluation?(hookContext: integrations.EvaluationHookContext, data: integrations.EvaluationHookData): integrations.EvaluationHookData;
20
+ afterEvaluation?(hookContext: integrations.EvaluationHookContext, data: integrations.EvaluationHookData, _detail: LDEvaluationDetail): integrations.EvaluationHookData;
21
+ }
22
+ //# sourceMappingURL=TracingHook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TracingHook.d.ts","sourceRoot":"","sources":["../src/TracingHook.ts"],"names":[],"mappings":"AAGA,OAAO,EAAW,YAAY,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAO1F;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;;;OAKG;IACH,KAAK,EAAE,OAAO,CAAC;CAChB;AAUD,MAAM,CAAC,OAAO,OAAO,WAAY,YAAW,YAAY,CAAC,IAAI;IAC3D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAC7C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA0C;gBAErD,OAAO,CAAC,EAAE,kBAAkB;IAIxC,WAAW,IAAI,YAAY,CAAC,YAAY;IAMxC,gBAAgB,CAAC,CACf,WAAW,EAAE,YAAY,CAAC,qBAAqB,EAC/C,IAAI,EAAE,YAAY,CAAC,kBAAkB,GACpC,YAAY,CAAC,kBAAkB;IAalC,eAAe,CAAC,CACd,WAAW,EAAE,YAAY,CAAC,qBAAqB,EAC/C,IAAI,EAAE,YAAY,CAAC,kBAAkB,EACrC,OAAO,EAAE,kBAAkB,GAC1B,YAAY,CAAC,kBAAkB;CAanC"}
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // eslint-disable-next-line max-classes-per-file
4
+ const api_1 = require("@opentelemetry/api");
5
+ const node_server_sdk_1 = require("@launchdarkly/node-server-sdk");
6
+ const FEATURE_FLAG_SCOPE = 'feature_flag';
7
+ const FEATURE_FLAG_KEY_ATTR = `${FEATURE_FLAG_SCOPE}.key`;
8
+ const FEATURE_FLAG_PROVIDER_ATTR = `${FEATURE_FLAG_SCOPE}.provider_name`;
9
+ const FEATURE_FLAG_CONTEXT_KEY = `${FEATURE_FLAG_SCOPE}.context.key`;
10
+ const defaultOptions = {
11
+ spans: false,
12
+ };
13
+ class TracingHook {
14
+ constructor(options) {
15
+ this.tracer = api_1.trace.getTracer('launchdarkly-client');
16
+ // TODO: Add option verification.
17
+ this.options = Object.assign(Object.assign({}, defaultOptions), (options !== null && options !== void 0 ? options : {}));
18
+ }
19
+ getMetadata() {
20
+ return {
21
+ name: 'LaunchDarkly Tracing Hook',
22
+ };
23
+ }
24
+ beforeEvaluation(hookContext, data) {
25
+ if (this.options.spans) {
26
+ const { canonicalKey } = node_server_sdk_1.Context.fromLDContext(hookContext.context);
27
+ const span = this.tracer.startSpan(hookContext.method, undefined, api_1.context.active());
28
+ span.setAttribute('feature_flag.context.key', canonicalKey);
29
+ span.setAttribute('feature_flag.key', hookContext.key);
30
+ return Object.assign(Object.assign({}, data), { span });
31
+ }
32
+ return data;
33
+ }
34
+ afterEvaluation(hookContext, data, _detail) {
35
+ var _a;
36
+ const currentTrace = api_1.trace.getActiveSpan();
37
+ if (currentTrace) {
38
+ currentTrace.addEvent(FEATURE_FLAG_SCOPE, {
39
+ [FEATURE_FLAG_KEY_ATTR]: hookContext.key,
40
+ [FEATURE_FLAG_PROVIDER_ATTR]: this.getMetadata().name,
41
+ [FEATURE_FLAG_CONTEXT_KEY]: node_server_sdk_1.Context.fromLDContext(hookContext.context).canonicalKey,
42
+ });
43
+ }
44
+ (_a = data.span) === null || _a === void 0 ? void 0 : _a.end();
45
+ return data;
46
+ }
47
+ }
48
+ exports.default = TracingHook;
49
+ //# sourceMappingURL=TracingHook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TracingHook.js","sourceRoot":"","sources":["../src/TracingHook.ts"],"names":[],"mappings":";;AAAA,gDAAgD;AAChD,4CAA0D;AAE1D,mEAA0F;AAE1F,MAAM,kBAAkB,GAAG,cAAc,CAAC;AAC1C,MAAM,qBAAqB,GAAG,GAAG,kBAAkB,MAAM,CAAC;AAC1D,MAAM,0BAA0B,GAAG,GAAG,kBAAkB,gBAAgB,CAAC;AACzE,MAAM,wBAAwB,GAAG,GAAG,kBAAkB,cAAc,CAAC;AAmBrE,MAAM,cAAc,GAAuB;IACzC,KAAK,EAAE,KAAK;CACb,CAAC;AAEF,MAAqB,WAAW;IAI9B,YAAY,OAA4B;QAFvB,WAAM,GAAG,WAAK,CAAC,SAAS,CAAC,qBAAqB,CAAC,CAAC;QAG/D,iCAAiC;QACjC,IAAI,CAAC,O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CC"}
@@ -0,0 +1,3 @@
1
+ export { default as TracingHook } from './TracingHook';
2
+ export { TracingHookOptions } from './TracingHook';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TracingHook = void 0;
4
+ var TracingHook_1 = require("./TracingHook");
5
+ Object.defineProperty(exports, "TracingHook", { enumerable: true, get: function () { return TracingHook_1.default; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,6CAAuD;AAA9C,0GAAA,OAAO,OAAe"}
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@launchdarkly/node-server-sdk-otel",
3
+ "version": "0.0.1",
4
+ "type": "commonjs",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "homepage": "https://github.com/launchdarkly/js-core/tree/main/packages/telemetry/node-server-sdk-otel",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/launchdarkly/js-core.git"
11
+ },
12
+ "description": "OpenTelemetry integration for the LaunchDarkly Server-Side SDK for Node.js",
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "keywords": [
17
+ "launchdarkly",
18
+ "analytics",
19
+ "client"
20
+ ],
21
+ "scripts": {
22
+ "doc": "../../../scripts/build-doc.sh .",
23
+ "test": "npx jest --ci",
24
+ "build": "npx tsc",
25
+ "clean": "npx tsc --build --clean",
26
+ "lint": "npx eslint . --ext .ts",
27
+ "lint:fix": "yarn run lint -- --fix",
28
+ "prettier": "prettier --write 'src/*.@(js|ts|tsx|json)'",
29
+ "check": "yarn && yarn prettier && yarn lint && tsc && yarn test"
30
+ },
31
+ "license": "Apache-2.0",
32
+ "peerDependencies": {
33
+ "@launchdarkly/node-server-sdk": "9.3.0-alpha.1",
34
+ "@opentelemetry/api": ">=1.3.0"
35
+ },
36
+ "devDependencies": {
37
+ "@launchdarkly/node-server-sdk": "9.3.0-alpha.1",
38
+ "@launchdarkly/private-js-mocks": "0.0.1",
39
+ "@opentelemetry/api": ">=1.3.0",
40
+ "@testing-library/dom": "^9.3.1",
41
+ "@testing-library/jest-dom": "^5.16.5",
42
+ "@types/jest": "^29.5.3",
43
+ "@types/semver": "^7.5.0",
44
+ "@typescript-eslint/eslint-plugin": "^6.20.0",
45
+ "@typescript-eslint/parser": "^6.20.0",
46
+ "eslint": "^8.45.0",
47
+ "eslint-config-airbnb-base": "^15.0.0",
48
+ "eslint-config-airbnb-typescript": "^17.1.0",
49
+ "eslint-config-prettier": "^8.8.0",
50
+ "eslint-plugin-import": "^2.27.5",
51
+ "eslint-plugin-jest": "^27.6.3",
52
+ "eslint-plugin-prettier": "^5.0.0",
53
+ "jest": "^29.6.1",
54
+ "jest-diff": "^29.6.1",
55
+ "jest-environment-jsdom": "^29.6.1",
56
+ "launchdarkly-js-test-helpers": "^2.2.0",
57
+ "prettier": "^3.0.0",
58
+ "ts-jest": "^29.1.1",
59
+ "typedoc": "0.25.0",
60
+ "typescript": "5.1.6"
61
+ }
62
+ }