Skip to content

Commit

Permalink
feat: Add OpenTelemetry support for node-server-sdk. (#401)
Browse files Browse the repository at this point in the history
  • Loading branch information
kinyoklion authored Apr 4, 2024
1 parent d120bec commit 485d635
Show file tree
Hide file tree
Showing 22 changed files with 636 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
name: '@launchdarkly/node-server-sdk-otel Bug Report'
about: Create a report to help us improve
title: ''
labels: 'package: telemetry/node-server-sdk-otel, bug'
assignees: ''
---

**Is this a support request?**
This issue tracker is maintained by LaunchDarkly SDK developers and is intended for feedback on the code in this library. If you're not sure whether the problem you are having is specifically related to this library, or to the LaunchDarkly service overall, it may be more appropriate to contact the LaunchDarkly support team; they can help to investigate the problem and will consult the SDK team if necessary. You can submit a support request by going [here](https://support.launchdarkly.com/) and clicking "submit a request", or by emailing [email protected].

Note that issues filed on this issue tracker are publicly accessible. Do not provide any private account information on your issues. If your problem is specific to your account, you should submit a support request as described above.

**Describe the bug**
A clear and concise description of what the bug is.

**To reproduce**
Steps to reproduce the behavior.

**Expected behavior**
A clear and concise description of what you expected to happen.

**Logs**
If applicable, add any log output related to your problem.

**SDK version**
The version of this SDK that you are using.

**Language version, developer tools**
For instance, Go 1.11 or Ruby 2.5.3. If you are using a language that requires a separate compiler, such as C, please include the name and version of the compiler too.

**OS/platform**
For instance, Ubuntu 16.04, Windows 10, or Android 4.0.3. If your code is running in a browser, please also include the browser type and version.

**Additional context**
Add any other context about the problem here.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: '@launchdarkly/node-server-sdk-otel Feature Request'
about: Suggest an idea for this project
title: ''
labels: 'package: telemetry/node-server-sdk-otel, feature'
assignees: ''
---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I would love to see the SDK [...does something new...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context about the feature request here.
1 change: 1 addition & 0 deletions .github/workflows/manual-publish-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ on:
- packages/sdk/akamai-edgekv
- packages/store/node-server-sdk-redis
- packages/store/node-server-sdk-dynamodb
- packages/telemetry/node-server-sdk-otel
name: Publish Documentation
jobs:
build-publish:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/manual-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ on:
- packages/sdk/akamai-edgekv
- packages/store/node-server-sdk-redis
- packages/store/node-server-sdk-dynamodb
- packages/telemetry/node-server-sdk-otel
prerelease:
description: 'Is this a prerelease. If so, then the latest tag will not be updated in npm.'
type: boolean
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/node-otel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: telemetry/node-server-sdk-otel

on:
push:
branches: [main, 'feat/**']
paths-ignore:
- '**.md' #Do not need to run CI for markdown changes.
pull_request:
branches: [main, 'feat/**']
paths-ignore:
- '**.md'

jobs:
build-test-node-server-otel:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
registry-url: 'https://registry.npmjs.org'
- id: shared
name: Shared CI Steps
uses: ./actions/ci
with:
workspace_name: '@launchdarkly/node-server-sdk-otel'
workspace_path: packages/telemetry/node-server-sdk-otel
28 changes: 26 additions & 2 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
package-akamai-edgekv-released: ${{ steps.release.outputs['packages/sdk/akamai-edgekv--release_created'] }}
package-node-server-sdk-redis-release: ${{ steps.release.outputs['packages/store/node-server-sdk-redis--release_created'] }}
package-node-server-sdk-dynamodb-release: ${{ steps.release.outputs['packages/store/node-server-sdk-dynamodb--release_created'] }}
package-node-server-sdk-otel-release: ${{ steps.release.outputs['packages/telemetry/node-server-sdk-otel--release_created'] }}
steps:
- uses: google-github-actions/release-please-action@v4
id: release
Expand Down Expand Up @@ -286,7 +287,7 @@ jobs:
permissions:
id-token: write
contents: write
if: ${{ needs.release-please.outputs.package-node-server-sdk-redis-release }}
if: ${{ needs.release-please.outputs.package-node-server-sdk-redis-release == 'true' }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
Expand All @@ -313,7 +314,7 @@ jobs:
permissions:
id-token: write
contents: write
if: ${{ needs.release-please.outputs.package-node-server-sdk-dynamodb-release }}
if: ${{ needs.release-please.outputs.package-node-server-sdk-dynamodb-release == 'true' }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
Expand All @@ -331,3 +332,26 @@ jobs:
with:
workspace_path: packages/store/node-server-sdk-dynamodb
aws_assume_role: ${{ vars.AWS_ROLE_ARN }}

release-node-server-sdk-otel:
runs-on: ubuntu-latest
needs: ['release-please']
permissions:
id-token: write
contents: write
if: ${{ needs.release-please.outputs.package-node-server-sdk-otel-release == 'true' }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16.x
registry-url: 'https://registry.npmjs.org'
- uses: ./actions/install-npm-version
with:
npm_version: 9.5.0
- id: release-node-server-sdk-otel
name: Full release of packages/telemetry/node-server-sdk-otel
uses: ./actions/full-release
with:
workspace_path: packages/telemetry/node-server-sdk-otel
aws_assume_role: ${{ vars.AWS_ROLE_ARN }}
3 changes: 2 additions & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"packages/store/node-server-sdk-dynamodb": "6.1.5",
"packages/store/node-server-sdk-redis": "4.1.5",
"packages/shared/sdk-client": "1.0.3",
"packages/sdk/react-native": "10.0.5"
"packages/sdk/react-native": "10.0.5",
"packages/telemetry/node-server-sdk-otel": "0.0.1"
}
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ This includes shared libraries, used by SDKs and other tools, as well as SDKs.
| [@launchdarkly/node-server-sdk-redis](packages/store/node-server-sdk-redis/README.md) | [![NPM][node-redis-npm-badge]][node-redis-npm-link] | [Node Redis][node-redis-issues] | [![Actions Status][node-redis-ci-badge]][node-redis-ci] |
| [@launchdarkly/node-server-sdk-dynamodb](packages/store/node-server-sdk-dynamodb/README.md) | [![NPM][node-dynamodb-npm-badge]][node-dynamodb-npm-link] | [Node DynamoDB][node-dynamodb-issues] | [![Actions Status][node-dynamodb-ci-badge]][node-dynamodb-ci] |

| Telemetry Packages | npm | issues | tests |
| ------------------------------------------------------------------------------------------- | --------------------------------------------------------- | ------------------------------------- | ------------------------------------------------------------- |
| [@launchdarkly/node-server-sdk-otel](packages/telemetry/node-server-sdk-otel/README.md) | [![NPM][node-otel-npm-badge]][node-otel-npm-link] | [Node OTel][node-otel-issues] | [![Actions Status][node-otel-ci-badge]][node-otel-ci] |

## Organization

`packages` Top level directory containing package implementations.
Expand All @@ -36,6 +40,8 @@ This includes shared libraries, used by SDKs and other tools, as well as SDKs.

`packages/store` Persistent store packages for use with SDKs in this repository.

`packages/telemetry` Packages for adding telemetry support to SDKs.

## LaunchDarkly overview

[LaunchDarkly](https://www.launchdarkly.com) is a feature management platform that serves trillions of feature flags daily to help teams build better software, faster. [Get started](https://docs.launchdarkly.com/home/getting-started) using LaunchDarkly today!
Expand Down Expand Up @@ -157,3 +163,9 @@ We encourage pull requests and other contributions from the community. Check out
[node-dynamodb-npm-badge]: https://img.shields.io/npm/v/@launchdarkly/node-server-sdk-dynamodb.svg?style=flat-square
[node-dynamodb-npm-link]: https://www.npmjs.com/package/@launchdarkly/node-server-sdk-dynamodb
[node-dynamodb-issues]: https://github.com/launchdarkly/js-core/issues?q=is%3Aissue+is%3Aopen+label%3A%22package%3A+store%2Fnode-server-sdk-dynamodb%22+
[//]: # 'telemetry/node-server-sdk-otel'
[node-otel-ci-badge]: https://github.com/launchdarkly/js-core/actions/workflows/node-otel.yml/badge.svg
[node-otel-ci]: https://github.com/launchdarkly/js-core/actions/workflows/node-otel.yml
[node-otel-npm-badge]: https://img.shields.io/npm/v/@launchdarkly/node-server-sdk-otel.svg?style=flat-square
[node-otel-npm-link]: https://www.npmjs.com/package/@launchdarkly/node-server-sdk-otel
[node-otel-issues]: https://github.com/launchdarkly/js-core/issues?q=is%3Aissue+is%3Aopen+label%3A%22package%3A+telemetry%2Fnode-server-sdk-otel%22+
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@
"packages/sdk/react-native",
"packages/sdk/react-native/example",
"packages/sdk/vercel",
"packages/sdk/vercel/examples/complete",
"packages/sdk/vercel/examples/route-handler",
"packages/sdk/akamai-base",
"packages/sdk/akamai-base/example",
"packages/sdk/akamai-edgekv",
"packages/sdk/akamai-edgekv/example",
"packages/store/node-server-sdk-redis",
"packages/store/node-server-sdk-dynamodb"
"packages/store/node-server-sdk-dynamodb",
"packages/telemetry/node-server-sdk-otel"
],
"private": true,
"scripts": {
Expand Down
13 changes: 13 additions & 0 deletions packages/telemetry/node-server-sdk-otel/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2024 Catamorphic, Co.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
69 changes: 69 additions & 0 deletions packages/telemetry/node-server-sdk-otel/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# LaunchDarkly Server-Side SDK for Node.js - OpenTelemetry integration

[![NPM][node-otel-npm-badge]][node-otel-npm-link]
[![Actions Status][node-otel-ci-badge]][node-otel-ci]
[![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/)

## LaunchDarkly overview

[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!

[![Twitter Follow](https://img.shields.io/twitter/follow/launchdarkly.svg?style=social&label=Follow&maxAge=2592000)](https://twitter.com/intent/follow?screen_name=launchdarkly)

## Supported Node versions

This package is compatible with Node.js versions 14 and above.

## Quick setup

This assumes that you have already installed the LaunchDarkly Node.js SDK.

1. Install this package with `npm` or `yarn`:

```shell
npm install @launchdarkly/node-server-sdk-otel --save
```

2. If your application does not already have its' own dependency on the `@opentelemetry/api` package, add `@opentelemetry/api` as well:

```shell
npm install @opentelemetry/api --save
```

3. Import the tracing hook:

```typescript
import { TracingHook } from '@launchdarkly/node-server-sdk-otel';
```

4. When configuring your SDK client, add the `TracingHook`

```typescript
import { init } from '@launchdarkly/node-server-sdk';

const client = init('YOUR SDK KEY', {hooks: [new TracingHook()]});
```

## Contributing

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.

## About LaunchDarkly

- 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:
- 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.
- 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?).
- 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.
- 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.
- 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.
- Explore LaunchDarkly
- [launchdarkly.com](https://www.launchdarkly.com/ 'LaunchDarkly Main Website') for more information
- [docs.launchdarkly.com](https://docs.launchdarkly.com/ 'LaunchDarkly Documentation') for our documentation and SDK reference guides
- [apidocs.launchdarkly.com](https://apidocs.launchdarkly.com/ 'LaunchDarkly API Documentation') for our API documentation
- [blog.launchdarkly.com](https://blog.launchdarkly.com/ 'LaunchDarkly Blog Documentation') for the latest product updates

[node-otel-ci-badge]: https://github.com/launchdarkly/js-core/actions/workflows/node-otel.yml/badge.svg
[node-otel-ci]: https://github.com/launchdarkly/js-core/actions/workflows/node-otel.yml
[node-otel-npm-badge]: https://img.shields.io/npm/v/@launchdarkly/node-server-sdk-otel.svg?style=flat-square
[node-otel-npm-link]: https://www.npmjs.com/package/@launchdarkly/node-server-sdk-otel
8 changes: 8 additions & 0 deletions packages/telemetry/node-server-sdk-otel/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
transform: { '^.+\\.ts?$': 'ts-jest' },
testMatch: ['**/*.test.ts?(x)'],
testEnvironment: 'node',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
collectCoverageFrom: ['src/**/*.ts'],
setupFilesAfterEnv: ['@launchdarkly/private-js-mocks/setup'],
};
63 changes: 63 additions & 0 deletions packages/telemetry/node-server-sdk-otel/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"name": "@launchdarkly/node-server-sdk-otel",
"version": "0.0.1",
"type": "commonjs",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"homepage": "https://github.com/launchdarkly/js-core/tree/main/packages/telemetry/node-server-sdk-otel",
"repository": {
"type": "git",
"url": "https://github.com/launchdarkly/js-core.git"
},
"description": "OpenTelemetry integration for the LaunchDarkly Server-Side SDK for Node.js",
"files": [
"dist"
],
"keywords": [
"launchdarkly",
"analytics",
"client"
],
"scripts": {
"doc": "../../../scripts/build-doc.sh .",
"test": "npx jest --ci",
"build": "npx tsc",
"clean": "npx tsc --build --clean",
"prettier": "prettier --write 'src/*.@(js|ts|tsx|json)'",
"check": "yarn && yarn prettier && yarn lint && tsc && yarn test",
"lint": "npx eslint . --ext .ts"
},
"license": "Apache-2.0",
"peerDependencies": {
"@launchdarkly/node-server-sdk": "9.2.2",
"@opentelemetry/api": ">=1.3.0"
},
"devDependencies": {
"@launchdarkly/node-server-sdk": "9.2.2",
"@launchdarkly/private-js-mocks": "0.0.1",
"@opentelemetry/api": ">=1.3.0",
"@opentelemetry/sdk-node": "0.49.1",
"@opentelemetry/sdk-trace-node": "1.22.0",
"@testing-library/dom": "^9.3.1",
"@testing-library/jest-dom": "^5.16.5",
"@types/jest": "^29.5.3",
"@types/semver": "^7.5.0",
"@typescript-eslint/eslint-plugin": "^6.20.0",
"@typescript-eslint/parser": "^6.20.0",
"eslint": "^8.45.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-airbnb-typescript": "^17.1.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-jest": "^27.6.3",
"eslint-plugin-prettier": "^5.0.0",
"jest": "^29.6.1",
"jest-diff": "^29.6.1",
"jest-environment-jsdom": "^29.6.1",
"launchdarkly-js-test-helpers": "^2.2.0",
"prettier": "^3.0.0",
"ts-jest": "^29.1.1",
"typedoc": "0.25.0",
"typescript": "5.1.6"
}
}
Loading

0 comments on commit 485d635

Please sign in to comment.