Skip to content
This repository has been archived by the owner on Nov 10, 2022. It is now read-only.

Commit

Permalink
fix: remove all circular dependencies (#119)
Browse files Browse the repository at this point in the history
* fix: remove all circular dependencies

* chore(deps): pin dpdm

Co-authored-by: Gerhard Stöbich <deb2001-github@yahoo.de>

* chore: better name for dpdm script

Co-authored-by: Gerhard Stöbich <deb2001-github@yahoo.de>
  • Loading branch information
dyladan and Flarna committed Aug 30, 2021
1 parent cbbbc96 commit a8083e8
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 26 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ jobs:
- name: Install dependencies
run: npm install

- name: Build 🔧
run: npm run compile

- name: Lint
run: npm run lint

- name: Build 🔧
run: npm run compile
- name: Check for Circular Dependencies
run: npm run cycle-check

- name: Generate Documentation 📜
run: npm run docs
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"lint": "eslint src test --ext .ts",
"test:browser": "nyc karma start --single-run",
"test": "nyc ts-mocha -p tsconfig.json test/**/*.test.ts",
"cycle-check": "dpdm --exit-code circular:1 src/index.ts",
"version": "node scripts/version-update.js",
"prewatch": "npm run version",
"watch": "tsc --build --watch"
Expand Down Expand Up @@ -63,6 +64,7 @@
"@typescript-eslint/eslint-plugin": "4.28.1",
"@typescript-eslint/parser": "4.28.1",
"codecov": "3.8.2",
"dpdm": "3.7.1",
"eslint": "7.30.0",
"eslint-plugin-header": "3.1.1",
"eslint-plugin-import": "2.23.4",
Expand Down
4 changes: 3 additions & 1 deletion src/baggage/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
* limitations under the License.
*/

import { diag } from '..';
import { DiagAPI } from '../api/diag';
import { BaggageImpl } from './internal/baggage-impl';
import { baggageEntryMetadataSymbol } from './internal/symbol';
import { Baggage, BaggageEntry, BaggageEntryMetadata } from './types';

const diag = DiagAPI.instance();

/**
* Create a new Baggage with optional entries
*
Expand Down
9 changes: 6 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,17 @@ export * from './trace/tracer_provider';
export * from './trace/tracer';

export {
INVALID_SPANID,
INVALID_TRACEID,
INVALID_SPAN_CONTEXT,
isSpanContextValid,
isValidTraceId,
isValidSpanId,
} from './trace/spancontext-utils';

export {
INVALID_SPANID,
INVALID_TRACEID,
INVALID_SPAN_CONTEXT,
} from './trace/invalid-span-constants';

export * from './context/context';
export * from './context/types';

Expand Down
5 changes: 2 additions & 3 deletions src/internal/global-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* limitations under the License.
*/

import type { DiagAPI } from '../api/diag';
import { ContextManager } from '../context/types';
import { DiagLogger } from '../diag';
import { _globalThis } from '../platform';
Expand All @@ -33,7 +32,7 @@ const _global = _globalThis as OTelGlobal;
export function registerGlobal<Type extends keyof OTelGlobalAPI>(
type: Type,
instance: OTelGlobalAPI[Type],
diag: DiagAPI,
diag: DiagLogger,
allowOverride = false
): boolean {
const api = (_global[GLOBAL_OPENTELEMETRY_API_KEY] = _global[
Expand Down Expand Up @@ -78,7 +77,7 @@ export function getGlobal<Type extends keyof OTelGlobalAPI>(
return _global[GLOBAL_OPENTELEMETRY_API_KEY]?.[type];
}

export function unregisterGlobal(type: keyof OTelGlobalAPI, diag: DiagAPI) {
export function unregisterGlobal(type: keyof OTelGlobalAPI, diag: DiagLogger) {
diag.debug(
`@opentelemetry/api: Unregistering a global for ${type} v${VERSION}.`
);
Expand Down
2 changes: 1 addition & 1 deletion src/trace/NonRecordingSpan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
import { Exception } from '../common/Exception';
import { TimeInput } from '../common/Time';
import { SpanAttributes } from './attributes';
import { INVALID_SPAN_CONTEXT } from './invalid-span-constants';
import { Span } from './span';
import { SpanContext } from './span_context';
import { SpanStatus } from './status';
import { INVALID_SPAN_CONTEXT } from './spancontext-utils';

/**
* The NonRecordingSpan is the default {@link Span} that is used when no Span
Expand Down
4 changes: 3 additions & 1 deletion src/trace/NoopTracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import { context } from '../';
import { ContextAPI } from '../api/context';
import { Context } from '../context/types';
import { getSpanContext, setSpan } from '../trace/context-utils';
import { NonRecordingSpan } from './NonRecordingSpan';
Expand All @@ -24,6 +24,8 @@ import { SpanOptions } from './SpanOptions';
import { SpanContext } from './span_context';
import { Tracer } from './tracer';

const context = ContextAPI.getInstance();

/**
* No-op implementations of {@link Tracer}.
*/
Expand Down
7 changes: 5 additions & 2 deletions src/trace/ProxyTracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import { Context } from '../context/types';
import { NoopTracer } from './NoopTracer';
import { ProxyTracerProvider } from './ProxyTracerProvider';
import { Span } from './span';
import { SpanOptions } from './SpanOptions';
import { Tracer } from './tracer';
Expand All @@ -31,7 +30,7 @@ export class ProxyTracer implements Tracer {
private _delegate?: Tracer;

constructor(
private _provider: ProxyTracerProvider,
private _provider: TracerDelegator,
public readonly name: string,
public readonly version?: string
) {}
Expand Down Expand Up @@ -69,3 +68,7 @@ export class ProxyTracer implements Tracer {
return this._delegate;
}
}

export interface TracerDelegator {
getDelegateTracer(name: string, version?: string): Tracer | undefined;
}
26 changes: 26 additions & 0 deletions src/trace/invalid-span-constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright The OpenTelemetry Authors
*
* 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
*
* https://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.
*/

import { SpanContext } from './span_context';
import { TraceFlags } from './trace_flags';

export const INVALID_SPANID = '0000000000000000';
export const INVALID_TRACEID = '00000000000000000000000000000000';
export const INVALID_SPAN_CONTEXT: SpanContext = {
traceId: INVALID_TRACEID,
spanId: INVALID_SPANID,
traceFlags: TraceFlags.NONE,
};
9 changes: 1 addition & 8 deletions src/trace/spancontext-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { INVALID_SPANID, INVALID_TRACEID } from './invalid-span-constants';
import { NonRecordingSpan } from './NonRecordingSpan';
import { Span } from './span';
import { SpanContext } from './span_context';
import { TraceFlags } from './trace_flags';

const VALID_TRACEID_REGEX = /^([0-9a-f]{32})$/i;
const VALID_SPANID_REGEX = /^[0-9a-f]{16}$/i;
export const INVALID_SPANID = '0000000000000000';
export const INVALID_TRACEID = '00000000000000000000000000000000';
export const INVALID_SPAN_CONTEXT: SpanContext = {
traceId: INVALID_TRACEID,
spanId: INVALID_SPANID,
traceFlags: TraceFlags.NONE,
};

export function isValidTraceId(traceId: string): boolean {
return VALID_TRACEID_REGEX.test(traceId) && traceId !== INVALID_TRACEID;
Expand Down
10 changes: 5 additions & 5 deletions test/trace/spancontext-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import * as assert from 'assert';
import * as context from '../../src/trace/spancontext-utils';
import { TraceFlags } from '../../src';
import { INVALID_SPANID, INVALID_TRACEID, TraceFlags } from '../../src';

describe('spancontext-utils', () => {
it('should return true for valid spancontext', () => {
Expand All @@ -30,7 +30,7 @@ describe('spancontext-utils', () => {

it('should return false when traceId is invalid', () => {
const spanContext = {
traceId: context.INVALID_TRACEID,
traceId: INVALID_TRACEID,
spanId: '6e0c63257de34c92',
traceFlags: TraceFlags.NONE,
};
Expand All @@ -40,16 +40,16 @@ describe('spancontext-utils', () => {
it('should return false when spanId is invalid', () => {
const spanContext = {
traceId: 'd4cda95b652f4a1592b449d5929fda1b',
spanId: context.INVALID_SPANID,
spanId: INVALID_SPANID,
traceFlags: TraceFlags.NONE,
};
assert.ok(!context.isSpanContextValid(spanContext));
});

it('should return false when traceId & spanId is invalid', () => {
const spanContext = {
traceId: context.INVALID_TRACEID,
spanId: context.INVALID_SPANID,
traceId: INVALID_TRACEID,
spanId: INVALID_SPANID,
traceFlags: TraceFlags.NONE,
};
assert.ok(!context.isSpanContextValid(spanContext));
Expand Down

0 comments on commit a8083e8

Please sign in to comment.