Closed Odinaka-git closed 7 months ago
A couple of things here.
1)
In opentelemetry-cpp 1.12.0, the following fix is not present:
This may affect which encoding is supported for the Authorization key/value pair.
2)
This code:
//provide the "OTEL_EXPORTER_OTLP_ENDPOINT" here. This is the endpoint your logs will be sent to.
logger_opts.url = std::string(std::getenv("OTEL_EXPORTER_OTLP_ENDPOINT")) + "/v1/logs";
is unnecessary, because opentelemetry-cpp does this by default, and even honor OTEL_EXPORTER_OTLP_LOGS_ENDPOINT
if present.
Beside, the code assumes OTEL_EXPORTER_OTLP_ENDPOINT
is provided, else it breaks with no fallback to a localhost default.
This is a side comments, that does not explain the failure.
3)
This code:
//provide the "OTEL_EXPORTER_OTLP_HEADERS" here. This is very important if you want to avoid authorization errors.
logger_opts.http_headers.insert(std::make_pair<const std::string, std::string>("Authorization", std::getenv("OTEL_EXPORTER_OTLP_HEADERS")));
is ill-formed.
Assuming the backend is graphana, documented at:
There are two ways to provide key/value pairs.
a)
First way is to provide a fully encoded OTEL_EXPORTER_OTLP_HEADERS environment variable, as described in the graphana doc.
The variable should look like:
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Basic XXXXXX"
or better (once using a release with the fix for #2579, not available yet)
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Basic%20XXXXXX"
and then the logger_opts.http_headers
member should be left unchanged, as opentelemetry-cpp will populate it from the env variable.
b)
Populate logger_opts.http_headers
programatically.
In this case, the key, which depends on the vendor, is Authorization
.
The key value is only Basic XXXXXX
or Basic%20XXXXXX
, not the full Authorization=Basic XXXXXX
string.
The full content of OTEL_EXPORTER_OTLP_HEADERS
was not disclosed in the issue report (and don't, it is sensitive data).
Assuming the value followed the vendor documentation, something like:
//provide the "OTEL_EXPORTER_OTLP_HEADERS" here. This is very important if you want to avoid authorization errors.
logger_opts.http_headers.insert(std::make_pair<const std::string, std::string>("Authorization", std::getenv("OTEL_EXPORTER_OTLP_HEADERS")));
combined with:
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Basic XXXXXX"
Will lead to key = Authorization
and value = Authorization=Basic XXXXXX
, which will fail in the HTTP OTLP backend.
oh, and thank you
This really isn't a bug report. I just wanted some help figuring out what might be missing from my code. I tried starting up discussions but I couldn't really find anyone who could give me an answer.
Describe your environment I running my application on a windows 11, and I'm using visual studio. The version of opentelemetry that I'm using is v1.12.0.
Steps to reproduce I have placed my Initlogger function here. This function is responsible for setting up my logger provider which will ship logs to grafana cloud.
Then this is the code that sends my logs in main
What is the expected behavior? I expect to see a 200 status code not a 204 status code
What is the actual behavior? I get a 204 status code instead.
Additional context This is what the error looks like