Skip to content
Merged

V3 #2

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
1 change: 0 additions & 1 deletion .codebeatignore

This file was deleted.

7 changes: 0 additions & 7 deletions .codebeatsettings

This file was deleted.

42 changes: 38 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,49 @@ name: Build

on:
push:
branches: [master]
tags: ['*']
pull_request:

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build:
quality:
name: Lint & format
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 24.x
cache: npm

- name: Install dependencies
run: npm ci

- name: Check formatting
run: npm run format:check

- name: Lint
run: npm run lint

test:
name: Test (Node ${{ matrix.node-version }})
runs-on: ubuntu-latest
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
node-version: [lts/*]

node-version: [22.x, 24.x]
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -20,9 +53,10 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: npm

- name: Install dependencies
run: npm install
run: npm ci

- name: Run tests
run: npm test
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ tslint.json
bin/
.git/
examples/
scripts/
.oxlintrc.json
.oxfmtrc.json
9 changes: 9 additions & 0 deletions .oxfmtrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"singleQuote": true,
"tabWidth": 4,
"printWidth": 80,
"semi": true,
"trailingComma": "all",
"arrowParens": "avoid",
"bracketSpacing": true
}
20 changes: 20 additions & 0 deletions .oxlintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"$schema": "./node_modules/oxlint/configuration_schema.json",
"categories": {
"correctness": "error"
},
"rules": {
"no-debugger": "error",
"no-console": ["warn", { "allow": ["warn", "error", "info"] }],
"no-unused-vars": "warn"
},
"ignorePatterns": [
"**/*.js",
"**/*.d.ts",
"docs/",
"coverage/",
".nyc_output/",
".agent-out/",
"node_modules/"
]
}
61 changes: 0 additions & 61 deletions eslint.config.mjs

This file was deleted.

61 changes: 34 additions & 27 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@
* purchase a proprietary commercial license. Please contact us at
* <support@imqueue.com> to get commercial licensing options.
*/
import {
Span,
trace,
SpanKind,
SpanStatusCode,
} from '@opentelemetry/api';
import { Span, trace, SpanKind, SpanStatusCode } from '@opentelemetry/api';
import * as path from 'path';
import {
SpanNames,
Expand Down Expand Up @@ -68,13 +63,13 @@ export function traceStart(
) {
if (traces[name]) {
throw new TypeError(
`Trace with name ${ name } has been already started!`,
`Trace with name ${name} has been already started!`,
);
}

traces[name] = trace.getTracer(
tracerName || defaultTracerName,
).startSpan(name);
traces[name] = trace
.getTracer(tracerName || defaultTracerName)
.startSpan(name);
}

// noinspection JSUnusedGlobalSymbols
Expand All @@ -97,8 +92,10 @@ const DEFAULT_TRACED_OPTIONS: TracedOptions = {
let pkgName = '';

try {
pkgName = require(`${ path.resolve('.') }${ path.sep }package.json`).name;
} catch (err) { /* ignore */ }
pkgName = require(`${path.resolve('.')}${path.sep}package.json`).name;
} catch {
/* ignore */
}

// noinspection JSUnusedGlobalSymbols
/**
Expand All @@ -113,35 +110,45 @@ export function traced(options?: Partial<TracedOptions>) {
) => {
const original = descriptor.value;
const opts: TracedOptions = Object.assign(
{}, DEFAULT_TRACED_OPTIONS, options || {},
{},
DEFAULT_TRACED_OPTIONS,
options || {},
);
const tracerInstance = trace.getTracer(
opts.tracerName || defaultTracerName,
);

descriptor.value = function<T>(...args: any[]) {
descriptor.value = function (...args: any[]) {
const className = this.constructor.name;
const attributes = Object.assign({
[AttributeNames.SPAN_KIND]: opts.kind,
[AttributeNames.RESOURCE_NAME]: `${ className }.${
String(methodName) }`,
...(pkgName ? { [AttributeNames.RESOURCE_NAME]: pkgName } : {}),
[AttributeNames.COMPONENT]: componentName,
}, opts.tags || {});
const attributes = Object.assign(
{
[AttributeNames.SPAN_KIND]: opts.kind,
[AttributeNames.RESOURCE_NAME]: `${className}.${String(
methodName,
)}`,
...(pkgName
? { [AttributeNames.RESOURCE_NAME]: pkgName }
: {}),
[AttributeNames.COMPONENT]: componentName,
},
opts.tags || {},
);
const span = tracerInstance.startSpan(SpanNames.METHOD_CALL, {
attributes,
kind: opts.kind === TraceKind.CLIENT
? SpanKind.CLIENT
: SpanKind.SERVER,
kind:
opts.kind === TraceKind.CLIENT
? SpanKind.CLIENT
: SpanKind.SERVER,
});

try {
const result: any = original && original.apply(this, args);

if (result && result.then) {
// noinspection CommaExpressionJS
return result.then((res: any) => (span.end(), res))
.catch((err: any) => handleError(span, err));
return result
.then((res: any) => (span.end(), res))
.catch((err: any) => handleError(span, err));
}

span.end();
Expand All @@ -167,4 +174,4 @@ function handleError(span: Span, err: any) {
span.end();

throw err;
}
}
Loading
Loading