Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Hooks and OpenTelemetry Support. #422

Merged
merged 6 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
24 changes: 24 additions & 0 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 @@ -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.7",
"packages/store/node-server-sdk-redis": "4.1.7",
"packages/shared/sdk-client": "1.1.1",
"packages/sdk/react-native": "10.1.1"
"packages/sdk/react-native": "10.1.1",
"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+
52 changes: 52 additions & 0 deletions contract-tests/TestHook.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import got from 'got';

export default class TestHook {
constructor(name, endpoint, data, errors) {
this._name = name;
this._endpoint = endpoint;
this._data = data;
this._errors = errors;
}

async _safePost(body) {
try {
await got.post(this._endpoint, { json: body });
} catch {
// The test could move on before the post, so we are ignoring
// failed posts.
}
}

getMetadata() {
return {
name: 'LaunchDarkly Tracing Hook',
};
}

beforeEvaluation(hookContext, data) {
if(this._errors?.beforeEvaluation) {
throw new Error(this._errors.beforeEvaluation);
}
this._safePost({
evaluationSeriesContext: hookContext,
evaluationSeriesData: data,
stage: 'beforeEvaluation',
});
return { ...data, ...(this._data?.['beforeEvaluation'] || {}) };
}

afterEvaluation(hookContext, data, detail) {
if(this._errors?.afterEvaluation) {
throw new Error(this._errors.afterEvaluation);
}
this._safePost({
evaluationSeriesContext: hookContext,
evaluationSeriesData: data,
stage: 'afterEvaluation',
evaluationDetail: detail,
});


return { ...data, ...(this._data?.['afterEvaluation'] || {}) };
}
}
1 change: 1 addition & 0 deletions contract-tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ app.get('/', (req, res) => {
'polling-gzip',
'inline-context',
'anonymous-redaction',
'evaluation-hooks',
],
});
});
Expand Down
7 changes: 7 additions & 0 deletions contract-tests/sdkClientEntity.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import ld, {

import BigSegmentTestStore from './BigSegmentTestStore.js';
import { Log, sdkLogger } from './log.js';
import TestHook from './TestHook.js';

const badCommandError = new Error('unsupported command');
export { badCommandError };
Expand All @@ -19,6 +20,7 @@ export function makeSdkConfig(options, tag) {
logger: sdkLogger(tag),
diagnosticOptOut: true,
};

const maybeTime = (seconds) =>
seconds === undefined || seconds === null ? undefined : seconds / 1000;
if (options.streaming) {
Expand Down Expand Up @@ -60,6 +62,11 @@ export function makeSdkConfig(options, tag) {
: undefined,
};
}
if (options.hooks) {
cf.hooks = options.hooks.hooks.map(
(hook) => new TestHook(hook.name, hook.callbackUri, hook.data, hook.errors),
);
}
return cf;
}

Expand Down
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
Loading
Loading