Skip to content

Commit

Permalink
Merge branch 'main' into metrics-ff/aggregation
Browse files Browse the repository at this point in the history
  • Loading branch information
dyladan authored Dec 9, 2021
2 parents 236463e + f51f853 commit 42bba7d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export class GrpcJsInstrumentation extends InstrumentationBase {
const instrumentation = this;
return (original: GrpcClientFunc) => {
instrumentation._diag.debug('patch all client methods');
return function clientMethodTrace(this: grpcJs.Client) {
function clientMethodTrace(this: grpcJs.Client) {
const name = `grpc.${original.path.replace('/', '')}`;
const args = [...arguments];
const metadata = getMetadata.call(
Expand All @@ -289,7 +289,9 @@ export class GrpcJsInstrumentation extends InstrumentationBase {
return context.with(trace.setSpan(context.active(), span), () =>
makeGrpcClientRemoteCall(original, args, metadata, this)(span)
);
};
}
Object.assign(clientMethodTrace, original);
return clientMethodTrace;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ export class GrpcNativeInstrumentation extends InstrumentationBase<
const instrumentation = this;
return (original: GrpcClientFunc) => {
instrumentation._diag.debug('patch all client methods');
return function clientMethodTrace(this: grpcTypes.Client) {
function clientMethodTrace(this: grpcTypes.Client) {
const name = `grpc.${(original.path as string | undefined)?.replace(
'/',
''
Expand All @@ -304,7 +304,9 @@ export class GrpcNativeInstrumentation extends InstrumentationBase<
this
)(span)
);
};
}
Object.assign(clientMethodTrace, original);
return clientMethodTrace;
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,16 @@ export const runTests = (
});
};

const runClientMethodTest = (
method: typeof methodList[0]
) => {
it(`should assign original properties for grpc remote method ${method.methodName}`, async () => {
const patchedClientMethod = (client as any)[method.methodName];
const properties = Object.keys(patchedClientMethod);
assert.ok(properties.length);
});
};

describe('enable()', () => {
const provider = new NodeTracerProvider();
provider.addSpanProcessor(new SimpleSpanProcessor(memoryExporter));
Expand Down Expand Up @@ -801,5 +811,30 @@ export const runTests = (
});
});
});

describe('Test assigning properties from original client method to patched client method', () => {
before(async () => {
plugin.disable();
plugin.setConfig({});
plugin.enable();

const packageDefinition = await protoLoader.load(PROTO_PATH, options);
const proto = grpc.loadPackageDefinition(packageDefinition).pkg_test;

client = createClient(grpc, proto);
});

after(done => {
client.close();
server.tryShutdown(() => {
plugin.disable();
done();
});
});

methodList.map(method => {
runClientMethodTest(method);
});
});
});
};

0 comments on commit 42bba7d

Please sign in to comment.