opentelemetry-js: Grpc OpenTelemetry Collector Exporter not showing traces with webpack
Please answer these questions before submitting a bug report.
What version of OpenTelemetry are you using?
"@opentelemetry/core": "^1.0.1",
"@opentelemetry/api": "^1.0.4",
"@opentelemetry/exporter-trace-otlp-grpc": "^0.27.0",
"@opentelemetry/resources": "1.0.1",
"@opentelemetry/sdk-metrics-base": "^0.27.0",
"@opentelemetry/sdk-trace-base": "^1.0.1",
"@opentelemetry/semantic-conventions": "1.0.1"
What version of Node are you using?
v16.13.2
Please provide the code you used to setup the OpenTelemetry SDK
Converted the sample app to ts
// tracing.ts
import opentelemetry from "@opentelemetry/api";
import { BasicTracerProvider, ConsoleSpanExporter, SimpleSpanProcessor } from "@opentelemetry/sdk-trace-base";
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-grpc";
import { SemanticResourceAttributes } from "@opentelemetry/semantic-conventions";
import { Resource } from "@opentelemetry/resources";
const exporter = new OTLPTraceExporter();
const provider = new BasicTracerProvider({
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: "basic-service",
}),
});
provider.addSpanProcessor(new SimpleSpanProcessor(exporter));
provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
provider.register();
const tracer = opentelemetry.trace.getTracer("example-otlp-exporter-node");
// Create a span. A span must be closed.
const parentSpan = tracer.startSpan("main");
for (let i = 0; i < 10; i += 1) {
doWork(parentSpan);
}
// Be sure to end the span.
parentSpan.end();
// give some time before it is closed
setTimeout(() => {
// flush and close the connection.
exporter.shutdown();
}, 2000);
function doWork(parent: any) {
// Start another span. In this example, the main method already started a
// span, so that'll be the parent span, and this will be a child span.
const ctx = opentelemetry.trace.setSpan(opentelemetry.context.active(), parent);
const span = tracer.startSpan("doWork", undefined, ctx);
// simulate some random work.
for (let i = 0; i <= Math.floor(Math.random() * 40000000); i += 1) {
// empty
}
// Set attributes to the span.
span.setAttribute("key", "value");
// Annotate our span to capture metadata about our operation
span.addEvent("invoking doWork");
// end span
span.end();
}
What did you do?
Added a webpack file, with the following content, and tried running the tracing on the dist/index.js file.
const path = require("path");
module.exports = {
entry: path.resolve(__dirname, "app.js"),
target: "node",
output: {
path: path.resolve(__dirname, "dist"),
filename: "index.js",
},
module: {
rules: [
{
test: /.(ts|js)$/,
loader: "ts-loader",
exclude: /node_modules/,
},
{ test: /\.node$/, loader: "node-loader" },
],
},
};
What did you expect to see?
I expected to see the tracing from both the Otel Exporter and Console Exporter.
What did you see instead?
The Otel Exporter traces are not showing in localhost:4317, only the console exporter displays in console.
Additional context
This warning is always displayed -
opentelemetry/proto/collector/trace/v1/trace_service.proto not found in any of the include paths js-app\protos
I tried moving the protos folder into the path the warning displays… solves nothing still.
The traces display fine without webpack.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 18 (10 by maintainers)
We’ve just hit this problem using opentelemetry with esbuild, it would be really helpful if the
protos
directory could be passed in as a parameter, so that we don’t have to artificially hoist them like this.It is possible to precompile .proto files into their json representations or to static JS but there are other considerations such as bundle size and performance impact there. The proto files are loaded by protobufjs to define the serialization format.
I think this is not a bug because it is known the gRPC doesn’t work in webpacked environments because of these proto files. There are workarounds like using a webpack plugin to copy the proto files. I’m changing this to a feature request as I view the request “please make the exporter work out of the box with webpack without configuration”
@shuhrat I just opened a PR that should take care of this #3705 🙂
I disagree that this is not a bug. Bundling is fairly common, and expecting libraries to support bundling is not entirely unreasonable.
The request is not that it work out of the box with webpack without configuration, but that it work with bundlers in general with a clearly documented workaround.
Such a workaround could be that https://github.com/open-telemetry/opentelemetry-js/blob/5d9ed3faa519279f2c68209a8ea9e1c213a4899e/experimental/packages/exporter-trace-otlp-grpc/src/util.ts#L40 also include
path.resolve(__dirname, 'protos')
and the documentation said that to work with a bundler, these files must be present- and give a location to get them from.The workaround we have used is to mark this entire module as external in esbuild and include a node_modules directory with this package in alongside our bundle.