-
Notifications
You must be signed in to change notification settings - Fork 650
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
Add Env variables in OTLP exporter #1101
Conversation
exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/exporter.py
Outdated
Show resolved
Hide resolved
exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/exporter.py
Outdated
Show resolved
Hide resolved
...ter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/metrics_exporter/__init__.py
Show resolved
Hide resolved
We need to wait for this PR for spec updates, so we follow the correct default for Also, for PR checklist:
|
exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/exporter.py
Outdated
Show resolved
Hide resolved
@jan25
This seems like an integration test. For a unit test, you simply need to test the constructor populates the desired fields for each use case, as well as your file opening logic works as expected for credentials. |
@jan25 is this still a WIP? |
@codeboten yes, I'll add unit tests and unmark WIP. Also, need to revert small changes i made assuming exporter changes will be merged. |
exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/exporter.py
Outdated
Show resolved
Hide resolved
credentials: ChannelCredentials object for server authentication | ||
metadata: Metadata to send when exporting | ||
""" | ||
|
||
def __init__( | ||
self, | ||
endpoint: str = "localhost:55680", | ||
endpoint: Optional[str] = None, | ||
insecure: Optional[bool] = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing protocol
, certificate_file
in constructor, compression
and timeout
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could add env vars for protocol
compression
when those usecases are implemented. Currently exporter uses grpc
only and no implementation for compression
.
certificate_file
is wrapped in ChannelCredentials object which is passed down from OTLPSpanExporter|MetricExporter
. I'll change timeout
logic to use env var too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Compression is implemented in a separate PR https://github.com/open-telemetry/opentelemetry-python/pull/1141/files#diff-77db88bbe988c1d7f7d9f92f9e05400259a026e7203f7e9ee12aef76b3b0fdb3R142
exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/exporter.py
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments.
Signed-off-by: Abhilash Gnan <abhilashgnan@gmail.com>
Signed-off-by: Abhilash Gnan <abhilashgnan@gmail.com>
Signed-off-by: Abhilash Gnan <abhilashgnan@gmail.com>
@jan25 looks like some tests are still failing, is the PR still a work in progress or is it ready for review? |
@codeboten Tests are failing on older Python versions due to unittest api changes, I've tried a few things but didn't succeed, I'll have to fix them. Otherwise this is ready to review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this looks pretty good! Just a request for change on the changelog. It would be good have information about the exporter environment variables in docs somewhere
- Update OpenTelemetry protos to v0.5.0 | ||
([#1143](https://github.com/open-telemetry/opentelemetry-python/pull/1143)) | ||
- Add Env variables in OTLP exporter | ||
([#1101](https://github.com/open-telemetry/opentelemetry-python/pull/1101)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be moved to unreleased
Signed-off-by: Abhilash Gnan <abhilashgnan@gmail.com>
Signed-off-by: Abhilash Gnan <abhilashgnan@gmail.com>
Signed-off-by: Abhilash Gnan <abhilashgnan@gmail.com>
@codeboten Thanks! I've fixed the tests and updated changelog too. Do you suggest we add a link to exporter-spec in |
I added a note to capture this work in the issue to review documentation, I don't want to block this PR on it and there are a bunch of places we need to review env variables anyways #1133 (comment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR looks great!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works, just leaving my comments about some UX issues I had today.
@@ -113,6 +116,16 @@ def _get_resource_data( | |||
return resource_data | |||
|
|||
|
|||
def _load_credential_from_file(filepath) -> ChannelCredentials: | |||
try: | |||
with open(filepath, "rb") as f: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried to use the OTLP Exporter today and I think I ran into an issue. If you don't have the OTEL_PYTHON_EXPORTER_OTLP_CERTIFICATE
Env variable set, then the call to Configuration().EXPORTER_OTLP_CERTIFICATE
will return None
instead of a String
. Then this line will throw error
TypeError: expected str, bytes or os.PathLike object, not NoneType
which is not caught by FileNotFoundError
below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest opening a new issue to track these problems instead of continuing an already closed PR thread.
"endpoint": endpoint | ||
or Configuration().EXPORTER_OTLP_SPAN_ENDPOINT, | ||
"insecure": insecure, | ||
"credentials": credentials, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I set OTLPExporter(insecure=True)
this works fine, but if I leave that out, I get a message
File "/Users/enowell/git/opentelemetry-python/exporter/opentelemetry-exporter-otlp/src/opentelemetry/exporter/otlp/exporter.py", line 178, in __init__
self._client = self._stub(secure_channel(endpoint, credentials))
File "/Users/enowell/Library/Python/3.8/lib/python/site-packages/grpc/__init__.py", line 1943, in secure_channel
if credentials._credentials is _insecure_channel_credentials:
AttributeError: 'NoneType' object has no attribute '_credentials'
which makes sense because insecure=None
and credentials=None
. I think a follow up would be to throw an Error Message if insecure=None (or False) && credentials=None
saying "Error: Either provide credentials or label as insecure."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@NathanielRN Thanks for reporting this. I also ran into this issue. Causes a failure in the example code.
@NathanielRN thanks for the review! I'll work on fixing them and open a PR. I couldn't think of way to add such case in unittests, will try again. |
…1101 (open-telemetry#1099) This addresses open-telemetry#1101 open-telemetry#752, and open-telemetry#1013 - Fix context loss when used in some async cases
Description
Adds support for Env variables in OTLP trace and metrics exporter. Implemented subset of variables from exporter spec, other variables will be implemented as the usecases are added to otlp exporter.
Fixes #1004 (issue)
Type of change
How Has This Been Tested?
Checklist: