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
26 changes: 26 additions & 0 deletions examples/grpc-census-prop/.eslintrc.js
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.
*/

'use strict';

const baseConfig = require('../../eslint.config');

module.exports = {
...baseConfig,
env: {
node: true,
},
};
1 change: 1 addition & 0 deletions examples/grpc-census-prop/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
33 changes: 28 additions & 5 deletions examples/grpc-census-prop/capitalize_client.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* 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.
*/

'use strict';

const api = require('@opentelemetry/api');
Expand All @@ -8,7 +24,10 @@ let tracer;
if (censusTracer) {
tracer = require('./tracer_census')();
} else {
tracer = require('./tracer')('example-grpc-capitalize-client', binaryPropagator);
tracer = require('./tracer')(
'example-grpc-capitalize-client',
binaryPropagator
);
}

const path = require('path');
Expand All @@ -27,7 +46,7 @@ const { Fetch } = grpc.load(PROTO_PATH).rpc;
function main() {
const client = new Fetch(
'localhost:50051',
grpc.credentials.createInsecure(),
grpc.credentials.createInsecure()
);
const data = process.argv[2] || 'opentelemetry';
console.log('> ', data);
Expand All @@ -41,15 +60,19 @@ function main() {
// The process must live for at least the interval past any traces that
// must be exported, or some risk being lost if they are recorded after the
// last export.
console.log('Sleeping 5 seconds before shutdown to ensure all records are flushed.');
setTimeout(() => { console.log('Completed.'); }, 5000);
console.log(
'Sleeping 5 seconds before shutdown to ensure all records are flushed.'
);
setTimeout(() => {
console.log('Completed.');
}, 5000);
}

/**
* Makes the gRPC call wrapped in an OpenCensus-style span
*/
function capitalizeWithCensusTracing(client, data) {
tracer.startRootSpan({ name: 'tutorialsClient.capitalize' }, (rootSpan) => {
tracer.startRootSpan({ name: 'tutorialsClient.capitalize' }, rootSpan => {
client.capitalize({ data: Buffer.from(data) }, (err, response) => {
if (err) {
console.log('could not get grpc response');
Expand Down
26 changes: 24 additions & 2 deletions examples/grpc-census-prop/capitalize_server.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* 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.
*/

'use strict';

/* eslint-disable global-require */
Expand All @@ -10,7 +26,10 @@ if (censusTracer) {
tracer = require('./tracer_census')();
({ SpanKind } = require('@opencensus/core'));
} else {
tracer = require('./tracer')('example-grpc-capitalize-server', binaryPropagator);
tracer = require('./tracer')(
'example-grpc-capitalize-server',
binaryPropagator
);
({ SpanKind } = require('@opentelemetry/api'));
}

Expand All @@ -20,7 +39,10 @@ const protoLoader = require('@grpc/proto-loader');

const PROTO_PATH = path.join(__dirname, 'protos/defs.proto');
const PROTO_OPTIONS = {
keepCase: true, enums: String, defaults: true, oneofs: true,
keepCase: true,
enums: String,
defaults: true,
oneofs: true,
};
const definition = protoLoader.loadSync(PROTO_PATH, PROTO_OPTIONS);
const rpcProto = grpc.loadPackageDefinition(definition).rpc;
Expand Down
2 changes: 2 additions & 0 deletions examples/grpc-census-prop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"description": "Example of using propagator-grpc-census-binary",
"main": "index.js",
"scripts": {
"lint": "eslint . --ext=ts,js,mjs",
"lint:fix": "eslint . --ext=ts,js,mjs --fix",
"server:otel:defprop": "cross-env node ./capitalize_server.js",
"server:otel:binprop": "cross-env BINARY_PROPAGATOR=true node ./capitalize_server.js",
"server:census": "cross-env CENSUS_TRACER=true node ./capitalize_server.js",
Expand Down
29 changes: 24 additions & 5 deletions examples/grpc-census-prop/tracer.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
/*
* 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.
*/

'use strict';

const opentelemetry = require('@opentelemetry/api');
const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
const { SimpleSpanProcessor, ConsoleSpanExporter } = require('@opentelemetry/sdk-trace-base');
const {
SimpleSpanProcessor,
ConsoleSpanExporter,
} = require('@opentelemetry/sdk-trace-base');
const { HttpTraceContextPropagator } = require('@opentelemetry/core');
const { GrpcCensusPropagator } = require('@opentelemetry/propagator-grpc-census-binary');
const {
GrpcCensusPropagator,
} = require('@opentelemetry/propagator-grpc-census-binary');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
const { GrpcInstrumentation } = require('@opentelemetry/instrumentation-grpc');

Expand Down Expand Up @@ -33,9 +54,7 @@ module.exports = (serviceName, binaryPropagator) => {
}

registerInstrumentations({
instrumentations: [
new GrpcInstrumentation(),
],
instrumentations: [new GrpcInstrumentation()],
});

return opentelemetry.trace.getTracer(serviceName);
Expand Down
17 changes: 16 additions & 1 deletion examples/grpc-census-prop/tracer_census.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* 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.
*/

'use strict';

const tracing = require('@opencensus/nodejs');
Expand All @@ -13,7 +29,6 @@ const defaultBufferConfig = {
*/
module.exports = () => {
const { tracer } = tracing.start({

samplingRate: 1,
plugins: {
grpc: '@opencensus/instrumentation-grpc',
Expand Down