bullmq-otel 1.0.0

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.
@@ -0,0 +1,36 @@
1
+ name: Release
2
+ on:
3
+ push:
4
+ branches:
5
+ - main
6
+
7
+ env:
8
+ HUSKY: 0
9
+
10
+ jobs:
11
+ release:
12
+ permissions:
13
+ contents: write # for release publishing
14
+
15
+ name: Release
16
+ env:
17
+ commitmsg: ${{ github.event.head_commit.message }}
18
+ runs-on: ubuntu-latest
19
+ steps:
20
+ - name: Checkout repository
21
+ uses: actions/checkout@v4
22
+ with:
23
+ fetch-depth: 0
24
+ - name: Setup Node.js
25
+ uses: actions/setup-node@v4
26
+ with:
27
+ node-version: lts/*
28
+ cache: 'yarn'
29
+ - name: Install dependencies Node
30
+ run: npm install --frozen-lockfile --non-interactive
31
+ - run: npm run build
32
+ - name: Release Node
33
+ env:
34
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35
+ NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
36
+ run: npx semantic-release
package/.prettierrc.js ADDED
@@ -0,0 +1,8 @@
1
+ module.exports = {
2
+ singleQuote: true,
3
+ trailingComma: "all",
4
+ tabWidth: 2,
5
+ printWidth: 80,
6
+ semi: true,
7
+ arrowParens: "avoid",
8
+ };
package/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ # 1.0.0 (2024-11-01)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **package.json:** typedoc and typscript to devDependencies ([15c2302](https://github.com/taskforcesh/bullmq-otel/commit/15c23026aa58dd0264f20f3b0b12b4f8ffbfe75f))
7
+
8
+
9
+ ### Features
10
+
11
+ * **BullMQOtel:** rename Otel to BullMQOtel and add devDependencies ([417fe82](https://github.com/taskforcesh/bullmq-otel/commit/417fe8269b42036cf7b41ce81ad9468be90dcaa8))
12
+ * implemente interface based on changes in BullMQ telemetry interface ([51d8ddd](https://github.com/taskforcesh/bullmq-otel/commit/51d8ddde968f11f860c29d033b6d10f7db519703))
13
+ * **Otel:** create first version of Otel interface ([9e5211d](https://github.com/taskforcesh/bullmq-otel/commit/9e5211d31b106d7a180339f778313a2852a15fb6))
14
+ * **Otel:** create first version of Otel interface ([85ee824](https://github.com/taskforcesh/bullmq-otel/commit/85ee8248b72b5e98630ca68a5e95ed25c5ea6485))
15
+ * **package.json:** add entrypoints for package ([4531b49](https://github.com/taskforcesh/bullmq-otel/commit/4531b49b2a59ca1a10a53981daf8f250e54c58fa))
@@ -0,0 +1,46 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ ## Our Standards
8
+
9
+ Examples of behavior that contributes to creating a positive environment include:
10
+
11
+ - Using welcoming and inclusive language
12
+ - Being respectful of differing viewpoints and experiences
13
+ - Gracefully accepting constructive criticism
14
+ - Focusing on what is best for the community
15
+ - Showing empathy towards other community members
16
+
17
+ Examples of unacceptable behavior by participants include:
18
+
19
+ - The use of sexualized language or imagery and unwelcome sexual attention or advances
20
+ - Trolling, insulting/derogatory comments, and personal or political attacks
21
+ - Public or private harassment
22
+ - Publishing others' private information, such as a physical or electronic address, without explicit permission
23
+ - Other conduct which could reasonably be considered inappropriate in a professional setting
24
+
25
+ ## Our Responsibilities
26
+
27
+ Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28
+
29
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30
+
31
+ ## Scope
32
+
33
+ This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34
+
35
+ ## Enforcement
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at admin@taskforce.sh. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38
+
39
+ Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40
+
41
+ ## Attribution
42
+
43
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44
+
45
+ [homepage]: http://contributor-covenant.org
46
+ [version]: http://contributor-covenant.org/version/1/4/
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 BullForce Labs AB
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # OpenTelemetry add-on for BullMQ
2
+
3
+ This module provides an OpenTelemetry implementation of BullMQ's telemetry interface.
4
+
5
+ ## Quick Guide
6
+
7
+ For information on how to use this module, please refer to the [Telemetry](https://docs.bullmq.io/guide/telemetry) section of the BullMQ documentation.
package/package.json ADDED
@@ -0,0 +1,99 @@
1
+ {
2
+ "name": "bullmq-otel",
3
+ "version": "1.0.0",
4
+ "description": "OpenTelemetry add-on for BullMQ",
5
+ "main": "./dist/cjs/index.js",
6
+ "module": "./dist/esm/index.js",
7
+ "types": "./dist/esm/index.d.ts",
8
+ "source": "./src/index.ts",
9
+ "scripts": {
10
+ "build": "tsc && tsc -p tsconfig-cjs.json",
11
+ "test": "echo \"Error: no test specified\" && exit 1",
12
+ "prepublishOnly": "npm run build",
13
+ "semantic-release": "semantic-release"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/taskforcesh/bullmq-otel.git"
18
+ },
19
+ "keywords": [
20
+ "telemetry",
21
+ "opentelemetry",
22
+ "otel",
23
+ "bullmq"
24
+ ],
25
+ "author": "BullForce Labs AB",
26
+ "license": "MIT",
27
+ "bugs": {
28
+ "url": "https://github.com/taskforcesh/bullmq-otel/issues"
29
+ },
30
+ "homepage": "https://github.com/taskforcesh/bullmq-otel#readme",
31
+ "dependencies": {
32
+ "@opentelemetry/api": "^1.9.0",
33
+ "bullmq": "^5.22.0"
34
+ },
35
+ "devDependencies": {
36
+ "@commitlint/cli": "^19.4.1",
37
+ "@commitlint/config-conventional": "^19.4.1",
38
+ "@semantic-release/changelog": "^6.0.3",
39
+ "@semantic-release/commit-analyzer": "^13.0.0",
40
+ "@semantic-release/git": "^10.0.1",
41
+ "@semantic-release/github": "^10.1.7",
42
+ "@semantic-release/npm": "^12.0.1",
43
+ "@semantic-release/release-notes-generator": "^14.0.1",
44
+ "tslib": "^2.8.0",
45
+ "typedoc": "^0.26.6",
46
+ "typescript": "^5.5.4"
47
+ },
48
+ "config": {
49
+ "commitizen": {
50
+ "path": "node_modules/cz-conventional-changelog"
51
+ }
52
+ },
53
+ "commitlint": {
54
+ "extends": [
55
+ "@commitlint/config-conventional"
56
+ ]
57
+ },
58
+ "release": {
59
+ "plugins": [
60
+ [
61
+ "@semantic-release/commit-analyzer",
62
+ {
63
+ "releaseRules": [
64
+ {
65
+ "message": "*\\[python\\]*",
66
+ "release": false
67
+ }
68
+ ]
69
+ }
70
+ ],
71
+ "@semantic-release/release-notes-generator",
72
+ [
73
+ "@semantic-release/changelog",
74
+ {
75
+ "changelogFile": "CHANGELOG.md"
76
+ }
77
+ ],
78
+ [
79
+ "@semantic-release/npm",
80
+ {
81
+ "npmPublish": true
82
+ }
83
+ ],
84
+ "@semantic-release/github",
85
+ [
86
+ "@semantic-release/git",
87
+ {
88
+ "assets": [
89
+ "package.json",
90
+ "yarn.lock",
91
+ "CHANGELOG.md",
92
+ "docs/gitbook/api/**"
93
+ ],
94
+ "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
95
+ }
96
+ ]
97
+ ]
98
+ }
99
+ }
@@ -0,0 +1,98 @@
1
+ import {
2
+ trace,
3
+ Tracer as OtelTracer,
4
+ ContextAPI,
5
+ context,
6
+ propagation,
7
+ Context as OtelContext,
8
+ Span as OtelSpan,
9
+ } from '@opentelemetry/api';
10
+
11
+ import {
12
+ ContextManager,
13
+ Telemetry,
14
+ Tracer,
15
+ Span,
16
+ AttributeValue,
17
+ Attributes,
18
+ Time,
19
+ Exception,
20
+ } from 'bullmq';
21
+
22
+ class BullMQOTelContextManager implements ContextManager<OtelContext> {
23
+ private contextAPI: ContextAPI = context;
24
+
25
+ getMetadata(ctx: OtelContext): string {
26
+ const metadata = {};
27
+ propagation.inject(ctx, metadata);
28
+ return JSON.stringify(metadata);
29
+ }
30
+
31
+ fromMetadata(activeCtx: OtelContext, metadata: string) {
32
+ const metadataObj = JSON.parse(metadata);
33
+ const ctx = propagation.extract(activeCtx, metadataObj);
34
+ return ctx;
35
+ }
36
+
37
+ with<A extends (...args: any[]) => any>(
38
+ ctx: OtelContext,
39
+ fn: A,
40
+ ): ReturnType<A> {
41
+ return this.contextAPI.with(ctx, fn);
42
+ }
43
+
44
+ active(): OtelContext {
45
+ return this.contextAPI.active();
46
+ }
47
+ }
48
+
49
+ class BullMQOtelTracer implements Tracer {
50
+ constructor(private tracer: OtelTracer) {}
51
+
52
+ startSpan(
53
+ name: string,
54
+ options?: any,
55
+ context?: OtelContext,
56
+ ): Span<OtelContext> {
57
+ const span = this.tracer.startSpan(name, options, context);
58
+ return new BullMQOTelSpan(span);
59
+ }
60
+ }
61
+
62
+ export class BullMQOTelSpan implements Span<OtelContext> {
63
+ constructor(public span: OtelSpan) {}
64
+
65
+ setSpanOnContext(ctx: OtelContext): OtelContext {
66
+ return trace.setSpan(ctx, this.span);
67
+ }
68
+
69
+ setAttribute(key: string, value: AttributeValue): void {
70
+ this.span.setAttribute(key, value);
71
+ }
72
+
73
+ setAttributes(attributes: Attributes): void {
74
+ this.span.setAttributes(attributes);
75
+ }
76
+
77
+ addEvent(name: string, attributes?: Attributes, time?: Time): void {
78
+ this.span.addEvent(name, attributes, time);
79
+ }
80
+
81
+ recordException(exception: Exception, time?: Time): void {
82
+ this.span.recordException(exception, time);
83
+ }
84
+
85
+ end(): void {
86
+ this.span.end();
87
+ }
88
+ }
89
+
90
+ export class BullMQOtel implements Telemetry<OtelContext> {
91
+ tracer: BullMQOtelTracer;
92
+ contextManager: BullMQOTelContextManager;
93
+
94
+ constructor(tracerName: string, version?: string) {
95
+ this.tracer = new BullMQOtelTracer(trace.getTracer(tracerName, version));
96
+ this.contextManager = new BullMQOTelContextManager();
97
+ }
98
+ }
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './bullMQOtel';
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "module": "node16",
5
+ "outDir": "dist/cjs",
6
+ "declaration": false,
7
+ "declarationDir": null,
8
+ "moduleResolution": "node16"
9
+ }
10
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "compilerOptions": {
3
+ "types": ["node"],
4
+ "target": "ES2017",
5
+ "module": "ES2020",
6
+ "incremental": true,
7
+ "declaration": true,
8
+ "outDir": "dist/esm",
9
+ "sourceMap": true,
10
+ "experimentalDecorators": true,
11
+ "emitDecoratorMetadata": true,
12
+ "strict": true,
13
+ "jsx": "preserve",
14
+ "importHelpers": true,
15
+ "moduleResolution": "node",
16
+ "esModuleInterop": false,
17
+ "allowSyntheticDefaultImports": false,
18
+ "strictNullChecks": false,
19
+ "baseUrl": ".",
20
+ "paths": {
21
+ "@src/*": ["src/*"]
22
+ },
23
+ "lib": ["esnext", "DOM"]
24
+ },
25
+ "include": ["src"],
26
+ "exclude": ["node_modules", "dist", "tests/*", "src/commands/*.ts"]
27
+ }