Skip to content

Commit

Permalink
move types to internal-types
Browse files Browse the repository at this point in the history
  • Loading branch information
pauloprestes committed Sep 11, 2023
1 parent 25f56af commit 0eea745
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,11 @@ import {
} from '@opentelemetry/instrumentation';

import type * as koa from 'koa';
import {
KoaMiddleware,
KoaContext,
KoaLayerType,
KoaInstrumentationConfig,
} from './types';
import { KoaInstrumentationConfig } from './types';
import { VERSION } from './version';
import { getMiddlewareMetadata, isLayerIgnored } from './utils';
import { getRPCMetadata, RPCType } from '@opentelemetry/core';
import { kLayerPatched, KoaPatchedMiddleware } from './internal-types';
import { KoaMiddleware, KoaLayerType, KoaContext, kLayerPatched, KoaPatchedMiddleware } from './internal-types';

/** Koa instrumentation for OpenTelemetry */
export class KoaInstrumentation extends InstrumentationBase<typeof koa> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,27 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { KoaMiddleware } from './types';

import type * as Router from '@koa/router';
import type { Middleware, ParameterizedContext, DefaultState } from 'koa';
import type { RouterParamContext } from '@koa/router';

export enum KoaLayerType {
ROUTER = 'router',
MIDDLEWARE = 'middleware',
}

export type KoaContext = ParameterizedContext<DefaultState, RouterParamContext>;

export type KoaRequestInfo = {
context: KoaContext;
middlewareLayer: Middleware<DefaultState, KoaContext>;
layerType: KoaLayerType;
};

export type KoaMiddleware = Middleware<DefaultState, KoaContext> & {
router?: Router;
};
/**
* This symbol is used to mark a Koa layer as being already instrumented
* since its possible to use a given layer multiple times (ex: middlewares)
Expand Down
21 changes: 1 addition & 20 deletions plugins/node/opentelemetry-instrumentation-koa/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import type { Middleware, ParameterizedContext, DefaultState } from 'koa';
import type { RouterParamContext } from '@koa/router';
import type * as Router from '@koa/router';
import { Span } from '@opentelemetry/api';
import { InstrumentationConfig } from '@opentelemetry/instrumentation';

export enum KoaLayerType {
ROUTER = 'router',
MIDDLEWARE = 'middleware',
}

export type KoaContext = ParameterizedContext<DefaultState, RouterParamContext>;

export type KoaMiddleware = Middleware<DefaultState, KoaContext> & {
router?: Router;
};

export type KoaRequestInfo = {
context: KoaContext;
middlewareLayer: Middleware<DefaultState, KoaContext>;
layerType: KoaLayerType;
};
import { KoaLayerType, KoaRequestInfo } from './internal-types';

/**
* Function that can be used to add custom attributes to the current span
Expand Down
4 changes: 1 addition & 3 deletions plugins/node/opentelemetry-instrumentation-koa/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@
* limitations under the License.
*/
import {
KoaContext,
KoaMiddleware,
KoaLayerType,
KoaInstrumentationConfig,
} from './types';
import { AttributeNames } from './enums/AttributeNames';
import { SpanAttributes } from '@opentelemetry/api';
import { SemanticAttributes } from '@opentelemetry/semantic-conventions';
import { KoaContext, KoaLayerType, KoaMiddleware } from './internal-types';

export const getMiddlewareMetadata = (
context: KoaContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import * as koa from 'koa';
import * as http from 'http';
import * as sinon from 'sinon';
import { AddressInfo } from 'net';
import { KoaLayerType, KoaRequestInfo } from '../src/types';
import { KoaLayerType, KoaRequestInfo } from '../src/internal-types';
import { AttributeNames } from '../src/enums/AttributeNames';
import { RPCMetadata, RPCType, setRPCMetadata } from '@opentelemetry/core';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

import * as utils from '../src/utils';
import * as assert from 'assert';
import { KoaInstrumentationConfig, KoaLayerType } from '../src/types';
import { KoaInstrumentationConfig } from '../src/types';
import { KoaLayerType } from '../src/internal-types';

describe('Utils', () => {
describe('isLayerIgnored()', () => {
Expand Down

0 comments on commit 0eea745

Please sign in to comment.