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(trace): implement otlp http backend #7

Merged
merged 4 commits into from
Dec 11, 2024
Merged

Conversation

GALLLASMILAN
Copy link
Contributor

@GALLLASMILAN GALLLASMILAN commented Dec 4, 2024

New OTLP backend

I implemented the custom OTLP backend that supports the HTTP-proto OpenTelemetry format a saves the Traces to the Observe (MongoDB) and MLflow.
See the docs/using-with-opentelemetry.md file for more info about integration with OpenTelemetry stack.

I changed the default port to 4318. This is the standard port for all OTLP backends for http-proto

The new routes are under the v1 prefix.

This is a breaking change with no backward compatibility. It's agreed with @matoushavlena

I added the new system route with the base data about versions and used environment variables. It's hidden in the Swagger

I use the bee-agent-framework directly in the integration tests.

Typescript files are automatically generated from the proto files copied from https://github.com/open-telemetry/opentelemetry-proto/tree/main/opentelemetry/proto

the traces/:id and spans routes return the trace by the frameworkTraceId provided from the framework context. It is the only one ID that we are able to save in both places (observe, bee-api) and then load the trace by this attribute.
We cannot process the POST v1/traces response right now the trace will be sent via the https://www.npmjs.com/package/@opentelemetry/sdk-node and the https://opentelemetry.io/docs/collector/

Release instructions

  • The ingress must be changed on the new port 4318.
  • The collector config must be updated.
  1. add the new exporter
  otlphttp:
    endpoint: <observe-url>
    compression: none
    headers:
      x-bee-authorization: "<AUTH_KEY>" 
  1. add this new otlphttp exporter to the exporters array in the service.pipelines.traces/dev section

Signed-off-by: GALLLASMILAN <gallas.milan@gmail.com>
src/app.ts Outdated
Comment on lines 50 to 55
// Custom parser for "application/x-protobuf"
app.addContentTypeParser(
'application/x-protobuf',
{ parseAs: 'buffer' },
traceProtobufBufferParser
);

Choose a reason for hiding this comment

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

It's weird that traceProfobufBufferParser parses anything protobuf.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I need to define the custom contentTypeParser, otherwise I get following:

OTLPExporterError: Unsupported Media Type
    at IncomingMessage.

error.
The traceProtobufBufferParser filters the parser logic only for the v1/traces route.

Copy link

@pilartomas pilartomas Dec 5, 2024

Choose a reason for hiding this comment

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

can you utilize this somehow?

As with the other APIs, addContentTypeParser is encapsulated in the scope in which it is declared. This means that if you declare it in the root scope it will be available everywhere, while if you declare it inside a plugin it will be available only in that scope and its children.

src/protos/trace_service.proto Show resolved Hide resolved
Comment on lines +82 to +83
export async function createTrace(traceBody: ExportTraceServiceRequest__Output): Promise<TraceDto> {
const spans = [...traceBody.resourceSpans].flatMap((resourceSpan) => {

Choose a reason for hiding this comment

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

I think it would also be good to check the instrumentation scope as a guardrail for unwanted data?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done in f1485c7

Choose a reason for hiding this comment

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

Why the filter, wouldn't you rather fail if you get invalid data?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, in case we send more data scopes on observe, it should be able to filter only the right one.

Signed-off-by: GALLLASMILAN <gallas.milan@gmail.com>
Signed-off-by: GALLLASMILAN <gallas.milan@gmail.com>
Signed-off-by: GALLLASMILAN <gallas.milan@gmail.com>
Copy link

@pilartomas pilartomas left a comment

Choose a reason for hiding this comment

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

Overall structure looks good.

jobs:
main:
timeout-minutes: 20
name: Lint & Build & Test
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: I don't see any test :D

@@ -6,7 +6,8 @@
"description": "Observability API server for bee-agent-framework",
"type": "module",
"scripts": {
"build": "rm -rf dist && tsc",
"build": "rm -rf dist && tsc && cp -R src/protos dist/protos",
"proto:generate": "proto-loader-gen-types --defaults --oneofs --longs=Number --enums=String --grpcLib=@grpc/grpc-js --outDir=./src/types/generated ./src/protos/*.proto && node scripts/add_js_extensions.js",
Copy link
Contributor

Choose a reason for hiding this comment

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

This is hacky, we already have a proper setup for generating proto types in the framework using tsup, please copy it from there

https://github.com/i-am-bee/bee-agent-framework/blob/main/scripts/ibm_vllm_generate_protos


const directory = path.resolve(__dirname, '../src/types/generated');

async function addJsExtensions(dir) {
Copy link
Contributor

Choose a reason for hiding this comment

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

not necessary with a proper tsup setup (see framework)

@@ -0,0 +1,81 @@
// Copyright 2019, OpenTelemetry Authors
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use the http version? @opentelemetry/exporter-trace-otlp-http

We're getting rid of protobufs in as many places as possible

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The observe uses the http proto right now. I generate the types from the proto files provided by the OpenTelemetry framework.
We will use the same proto files for the grpc server in the future.
The HTTP proto with the default port 4318 is only one part the the standard OTLP server. The second part is grpc server on port 4317 that should be implemented later

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The second thing, is I need to parse protobuf to json.

Copy link
Contributor

@jezekra1 jezekra1 left a comment

Choose a reason for hiding this comment

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

Agreed offline that protofile type generation will be addressed later in a separate PR

@matoushavlena matoushavlena merged commit 1296ef5 into main Dec 11, 2024
2 checks passed
@matoushavlena matoushavlena deleted the otlp-http-backend branch December 11, 2024 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants