Skip to content
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
15 changes: 9 additions & 6 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@
* 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 { readFileSync } from 'node:fs';
import { type Span, trace, SpanKind, SpanStatusCode } from '@opentelemetry/api';
import * as path from 'path';
import {
SpanNames,
TraceKind,
TracedOptions,
type TracedOptions,
AttributeNames,
TraceAttributes,
} from './src';
type TraceAttributes,
} from './src/index.js';

export * from './src/instrumentation';
export * from './src/instrumentation.js';

const traces: { [name: string]: Span } = {};
const componentName = 'imq';
Expand Down Expand Up @@ -92,7 +93,9 @@ const DEFAULT_TRACED_OPTIONS: TracedOptions = {
let pkgName = '';

try {
pkgName = require(`${path.resolve('.')}${path.sep}package.json`).name;
pkgName = JSON.parse(
readFileSync(`${path.resolve('.')}${path.sep}package.json`, 'utf8'),
).name;
} catch {
/* ignore */
}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 13 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@imqueue/opentelemetry-instrumentation-imqueue",
"version": "3.0.0",
"version": "3.1.0",
"description": "This module provides OpenTelemetry instrumentation for @imqueue",
"keywords": [
"imqueue",
Expand Down Expand Up @@ -50,5 +50,16 @@
"typescript": "^7.0.2"
},
"main": "index.js",
"types": "index.d.ts"
"types": "index.d.ts",
"type": "module",
"engines": {
"node": ">=22.12.0"
},
"exports": {
".": {
"types": "./index.d.ts",
"default": "./index.js"
},
"./package.json": "./package.json"
}
}
6 changes: 3 additions & 3 deletions src/enums/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
* purchase a proprietary commercial license. Please contact us at
* <support@imqueue.com> to get commercial licensing options.
*/
export * from './TraceKind';
export * from './AttributeNames';
export * from './SpanNames';
export * from './TraceKind.js';
export * from './AttributeNames.js';
export * from './SpanNames.js';
2 changes: 1 addition & 1 deletion src/imq/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
import { Span } from '@opentelemetry/api';
import { type Span } from '@opentelemetry/api';

export interface IMQClient {
name: string;
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
* purchase a proprietary commercial license. Please contact us at
* <support@imqueue.com> to get commercial licensing options.
*/
export * from './instrumentation';
export * from './types';
export * from './enums';
export * from './instrumentation.js';
export * from './types.js';
export * from './enums/index.js';
19 changes: 13 additions & 6 deletions src/instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,24 @@
*/
import {
InstrumentationBase,
InstrumentationConfig,
type InstrumentationConfig,
InstrumentationNodeModuleDefinition,
} from '@opentelemetry/instrumentation';
import { IMQClient, IMQRPCRequest, IMQServiceOptions } from './imq/types';
import {
type IMQClient,
type IMQRPCRequest,
type IMQServiceOptions,
} from './imq/types.js';
import {
context,
propagation,
SpanKind,
trace,
Tracer,
type Tracer,
} from '@opentelemetry/api';
import { AttributeNames, SpanNames, TraceKind } from './enums';
import path from 'path';
import { AttributeNames, SpanNames, TraceKind } from './enums/index.js';
import { readFileSync } from 'node:fs';
import path from 'node:path';

let packageJson: { name: string; version: string };
let instrumentationName = '@imqueue/opentelemetry-instrumentation-imqueue';
Expand All @@ -37,7 +42,9 @@ const versions = ['>=1.10'];
const componentName = 'imq';

try {
packageJson = require(`${path.resolve('.')}${path.sep}package.json`);
packageJson = JSON.parse(
readFileSync(`${path.resolve('.')}${path.sep}package.json`, 'utf8'),
);
instrumentationName = packageJson.name;
instrumentationVersion = packageJson.version;
} catch {
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* purchase a proprietary commercial license. Please contact us at
* <support@imqueue.com> to get commercial licensing options.
*/
import { TraceKind } from './enums';
import { TraceKind } from './enums/index.js';

export interface TracedOptions {
kind: TraceKind;
Expand Down
30 changes: 17 additions & 13 deletions test/instrumentation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
*/
import { describe, it, type TestContext } from 'node:test';
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { propagation, trace } from '@opentelemetry/api';
import { IMQClient, IMQRPCRequest } from '../src/imq/types';
import { ImqueueInstrumentation } from '..';
import { type IMQClient, type IMQRPCRequest } from '../src/imq/types.js';
import { ImqueueInstrumentation } from '../index.js';

const self = require('../package.json');
const self = JSON.parse(
readFileSync(new URL('../package.json', import.meta.url), 'utf8'),
);

const client: IMQClient = {
name: 'client-name',
Expand Down Expand Up @@ -89,25 +92,26 @@ describe('ImqueueInstrumentation', () => {
assert.equal(instrumentation.instrumentationVersion, self.version);
});

it('should fall back to defaults when no package.json exists', () => {
it('should fall back to defaults when no package.json exists', async () => {
const cwd = process.cwd();
const modulePath = require.resolve('../src/instrumentation');

delete require.cache[modulePath];
process.chdir(tmpdir());

try {
// a fresh module load from a directory without package.json
// exercises the fallback branch
const {
ImqueueInstrumentation: Fallback,
} = require('../src/instrumentation');
// a fresh, query-busted copy evaluates from a directory
// without package.json, exercising the fallback branch (the
// ES module registry is immutable, hence the unique URL)
const href = new URL(
'../src/instrumentation.js',
import.meta.url,
).href;
const { ImqueueInstrumentation: Fallback } = await import(
`${href}?fallback=1`
);

assert.ok(new Fallback() instanceof Fallback);
} finally {
process.chdir(cwd);
delete require.cache[modulePath];
require('../src/instrumentation');
}
});
});
Expand Down
7 changes: 5 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"compilerOptions": {
"target": "es2023",
"lib": ["es2023"],
"target": "es2024",
"lib": ["es2024"],
"moduleDetection": "force",

"module": "nodenext",
"moduleResolution": "nodenext",
"resolveJsonModule": true,
"esModuleInterop": true,
"verbatimModuleSyntax": true,

"types": ["node"],

Expand All @@ -19,6 +20,8 @@
"removeComments": false,
"newLine": "lf",

"skipLibCheck": true,

"strict": true,
"noImplicitOverride": true,
"noFallthroughCasesInSwitch": true
Expand Down
Loading