Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugin): add grpc plugin #215

Merged
merged 19 commits into from
Sep 11, 2019
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 2 additions & 0 deletions packages/opentelemetry-node-tracer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

export * from './NodeTracer';
10 changes: 8 additions & 2 deletions packages/opentelemetry-plugin-grpc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"types": "build/src/index.d.ts",
"repository": "open-telemetry/opentelemetry-js",
"scripts": {
"test": "nyc ts-mocha -p tsconfig.json test/**/*.ts",
"test": "nyc ts-mocha -p tsconfig.json test/**/*.test.ts",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to keep it standardized everywhere, either change all packages script to test/**/*.test.ts or keep it test/**/*.ts. WDYT?

"tdd": "yarn test -- --watch-extensions ts --watch",
"clean": "rimraf build/*",
"check": "gts check",
Expand Down Expand Up @@ -40,7 +40,10 @@
"devDependencies": {
"@types/mocha": "^5.2.7",
"@types/node": "^12.6.9",
"@types/protobufjs": "^6.0.0",
"@types/shimmer": "^1.0.1",
"codecov": "^3.5.0",
"grpc": "1.22.2",
mayurkale22 marked this conversation as resolved.
Show resolved Hide resolved
"gts": "^1.1.0",
"mocha": "^6.2.0",
"nyc": "^14.1.1",
Expand All @@ -51,6 +54,9 @@
"dependencies": {
"@opentelemetry/core": "^0.0.1",
"@opentelemetry/node-tracer": "^0.0.1",
"@opentelemetry/types": "^0.0.1"
"@opentelemetry/scope-async-hooks": "^0.0.1",
"@opentelemetry/types": "^0.0.1",
"semver": "^6.3.0",
"shimmer": "^1.2.1"
}
}
24 changes: 24 additions & 0 deletions packages/opentelemetry-plugin-grpc/src/enums/grpcAttributeNames.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* Copyright 2019, 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.
*/

export enum GrpcAttributeNames {
mayurkale22 marked this conversation as resolved.
Show resolved Hide resolved
COMPONENT = 'grpc.component',
GRPC_KIND = 'grpc.kind', // SERVER or CLIENT
GRPC_METHOD = 'grpc.method',
GRPC_STATUS_CODE = 'grpc.status_code',
GRPC_ERROR_NAME = 'grpc.error_name',
GRPC_ERROR_MESSAGE = 'grpc.error_message',
}
71 changes: 71 additions & 0 deletions packages/opentelemetry-plugin-grpc/src/grpc-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
mayurkale22 marked this conversation as resolved.
Show resolved Hide resolved
* Copyright 2019, 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 * as grpcModule from 'grpc';
import * as events from 'events';

export type grpc = typeof grpcModule;

export type SendUnaryDataCallback = (
error: grpcModule.ServiceError | null,
// tslint:disable-next-line:no-any
value?: any,
trailer?: grpcModule.Metadata,
flags?: grpcModule.writeFlags
) => void;

export interface GrpcPluginOptions {}

interface GrpcStatus {
code: number;
details: string;
metadata: grpcModule.Metadata;
}

export type ServerCall =
| typeof grpcModule.ServerUnaryCall
| typeof grpcModule.ServerReadableStream
| typeof grpcModule.ServerWriteableStream
| typeof grpcModule.ServerDuplexStream;

export type ServerCallWithMeta = ServerCall & {
metadata: grpcModule.Metadata;
status: GrpcStatus;
// tslint:disable-next-line:no-any
request?: any;
} & events.EventEmitter;

export type GrpcClientFunc = typeof Function & {
path: string;
requestStream: boolean;
responseStream: boolean;
};

// TODO: Delete if moving internal file loaders to BasePlugin
/**
* Maps a name (key) representing a internal file module and its exports
*/
export interface ModuleNameToFilePath {
client: string; // path/to/file
[wildcard: string]: string; // string indexer
}

/**
* Maps a semver to a module:filepath Map
*/
export interface ModuleExportsMapping {
[semver: string]: ModuleNameToFilePath;
}
30 changes: 30 additions & 0 deletions packages/opentelemetry-plugin-grpc/src/grpc-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* Copyright 2019, 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.
*/

// Equivalent to lodash _.findIndex
export const findIndex: <T>(args: T[], fn: (arg: T) => boolean) => number = (
args,
fn: Function
) => {
let index = -1;
for (const arg of args) {
index++;
if (fn(arg)) {
return index;
}
}
return -1;
};
Loading