Automatic exporter/provider setup for opentelemetry-instrument command.#1036
Automatic exporter/provider setup for opentelemetry-instrument command.#1036codeboten merged 1 commit intoopen-telemetry:masterfrom
Conversation
1568630 to
05a1fed
Compare
53a5233 to
0ec2526
Compare
open-telemetry#1036 This commit adds support to the opentelemetry-instrument command to automatically configure a tracer provider and exporter. By default, it configures the OTLP exporter (like other Otel auto-instrumentations. e.g, Java: https://github.com/open-telemetry/opentelemetry-java-instrumentation#getting-started). It also allows using a different in-built or 3rd party via a CLI argument or env variable. Details can be found on opentelemetry-instrumentation's README package. Fixes open-telemetry#663
open-telemetry#1036 This commit adds support to the opentelemetry-instrument command to automatically configure a tracer provider and exporter. By default, it configures the OTLP exporter (like other Otel auto-instrumentations. e.g, Java: https://github.com/open-telemetry/opentelemetry-java-instrumentation#getting-started). It also allows using a different in-built or 3rd party via a CLI argument or env variable. Details can be found on opentelemetry-instrumentation's README package. Fixes open-telemetry#663
open-telemetry#1036 This commit adds support to the opentelemetry-instrument command to automatically configure a tracer provider and exporter. By default, it configures the OTLP exporter (like other Otel auto-instrumentations. e.g, Java: https://github.com/open-telemetry/opentelemetry-java-instrumentation#getting-started). It also allows using a different in-built or 3rd party via a CLI argument or env variable. Details can be found on opentelemetry-instrumentation's README package. Fixes open-telemetry#663
open-telemetry#1036 This commit adds support to the opentelemetry-instrument command to automatically configure a tracer provider and exporter. By default, it configures the OTLP exporter (like other Otel auto-instrumentations. e.g, Java: https://github.com/open-telemetry/opentelemetry-java-instrumentation#getting-started). It also allows using a different in-built or 3rd party via a CLI argument or env variable. Details can be found on opentelemetry-instrumentation's README package. Fixes open-telemetry#663
open-telemetry#1036 This commit adds support to the opentelemetry-instrument command to automatically configure a tracer provider and exporter. By default, it configures the OTLP exporter (like other Otel auto-instrumentations. e.g, Java: https://github.com/open-telemetry/opentelemetry-java-instrumentation#getting-started). It also allows using a different in-built or 3rd party via a CLI argument or env variable. Details can be found on opentelemetry-instrumentation's README package. Fixes open-telemetry#663
open-telemetry#1036 This commit adds support to the opentelemetry-instrument command to automatically configure a tracer provider and exporter. By default, it configures the OTLP exporter (like other Otel auto-instrumentations. e.g, Java: https://github.com/open-telemetry/opentelemetry-java-instrumentation#getting-started). It also allows using a different in-built or 3rd party via a CLI argument or env variable. Details can be found on opentelemetry-instrumentation's README package. Fixes open-telemetry#663
open-telemetry#1036 This commit adds support to the opentelemetry-instrument command to automatically configure a tracer provider and exporter. By default, it configures the OTLP exporter (like other Otel auto-instrumentations. e.g, Java: https://github.com/open-telemetry/opentelemetry-java-instrumentation#getting-started). It also allows using a different in-built or 3rd party via a CLI argument or env variable. Details can be found on opentelemetry-instrumentation's README package. Fixes open-telemetry#663
open-telemetry#1036 This commit adds support to the opentelemetry-instrument command to automatically configure a tracer provider and exporter. By default, it configures the OTLP exporter (like other Otel auto-instrumentations. e.g, Java: https://github.com/open-telemetry/opentelemetry-java-instrumentation#getting-started). It also allows using a different in-built or 3rd party via a CLI argument or env variable. Details can be found on opentelemetry-instrumentation's README package. Fixes open-telemetry#663
open-telemetry#1036 This commit adds support to the opentelemetry-instrument command to automatically configure a tracer provider and exporter. By default, it configures the OTLP exporter (like other Otel auto-instrumentations. e.g, Java: https://github.com/open-telemetry/opentelemetry-java-instrumentation#getting-started). It also allows using a different in-built or 3rd party via a CLI argument or env variable. Details can be found on opentelemetry-instrumentation's README package. Fixes open-telemetry#663
open-telemetry#1036 This commit adds support to the opentelemetry-instrument command to automatically configure a tracer provider and exporter. By default, it configures the OTLP exporter (like other Otel auto-instrumentations. e.g, Java: https://github.com/open-telemetry/opentelemetry-java-instrumentation#getting-started). It also allows using a different in-built or 3rd party via a CLI argument or env variable. Details can be found on opentelemetry-instrumentation's README package. Fixes open-telemetry#663
open-telemetry#1036 This commit adds support to the opentelemetry-instrument command to automatically configure a tracer provider and exporter. By default, it configures the OTLP exporter (like other Otel auto-instrumentations. e.g, Java: https://github.com/open-telemetry/opentelemetry-java-instrumentation#getting-started). It also allows using a different in-built or 3rd party via a CLI argument or env variable. Details can be found on opentelemetry-instrumentation's README package. Fixes open-telemetry#663
open-telemetry#1036 This commit adds support to the opentelemetry-instrument command to automatically configure a tracer provider and exporter. By default, it configures the OTLP exporter (like other Otel auto-instrumentations. e.g, Java: https://github.com/open-telemetry/opentelemetry-java-instrumentation#getting-started). It also allows using a different in-built or 3rd party via a CLI argument or env variable. Details can be found on opentelemetry-instrumentation's README package. Fixes open-telemetry#663
dac8060 to
e2a1a04
Compare
Update:This PR now only support two configuration options.
This options takes a comma separated list of exporter names and automatically configures these exporters. In addition to the well-known exporters (ones present in this repo), it also accepts qualified Python paths to valid exporters. It accepts metric exporters but does nothing with them right now. Support for auto configuring metrics pipeline will be added later.
This value is used to configure the given exporter and/or provider with a service name. @open-telemetry/python-approvers |
|
Further simplified this by removing new features added to the bootstrap command (ability to install exporters). I'll follow up with a separate PR for that. |
| } | ||
|
|
||
|
|
||
| def _import(import_path: str) -> any: |
There was a problem hiding this comment.
May I recommend not relying on import paths but to use standard entry points? This is an example.
|
|
||
| if ( | ||
| hasattr(sys, "argv") | ||
| and sys.argv[0].split(os.path.sep)[-1] == "celery" |
There was a problem hiding this comment.
Can this be moved to the celery instrumentation package?
There was a problem hiding this comment.
We could do that and then pass argv to a function from the celery instrumentation package but I don't see much benefit in that. It is a special case in real life so probably we should live with the fact and allow it. Also, we initialize entire tracing pipeline here and instrument all packages, not just celery so not sure if celery instrumentation having this would be the right choice.
Also, this is orthogonal to celery instrumentation really. Users might not have celery instrumentation installed but might still want their celery process to be traced (manually or through other instrumentation packages) and that's what this helps with. Without this, batch span exporter does not work with celery workers.
There was a problem hiding this comment.
This PR has been open for a while, so in order to move forward I am ok with this as it is right now. Nevertheless, I think we should definitely keep the "core" instrumentation completely separated from the implementation details of any and all of the instrumentation packages. This probably means allowing all the instrumentation packages to be allowed to run a preregistered function or something similar that includes this kind of code.
...etry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/sitecustomize.py
Show resolved
Hide resolved
...lemetry-instrumentation/src/opentelemetry/instrumentation/auto_instrumentation/components.py
Show resolved
Hide resolved
|
|
||
| _DEFAULT_EXPORTER = symbols.exporter_otlp | ||
|
|
||
| known_exporters = { |
There was a problem hiding this comment.
If I understand this correctly, this is mapping certain strings to an import path of classes that already exist in our repo, with the purpose of instantiating these classes when their matching keys are passed as arguments via CLI. Using entry points would save us from having to implement this by hand, as this is basically what the entry points mechanism does, it associates a certain string defined in the setup.cfg to a Python object, which can be the class. This approach has the advantage that it keeps the plugins (the code related to the specific library or exporter in this case) separated from the code of the "core" opentelemetry-instrumentation component.
There was a problem hiding this comment.
Thanks. That might work. I like that it means installing any compatible package will automatically add support for the specific package to the instrument command. I'll see if it has everything we need.
|
Hello! I have a PR to move some files you have in this PR to the Contrib repo, please let me know if this gets merged before the PR in the Contrib repo. Please see https://github.com/open-telemetry/opentelemetry-python-contrib/pulls/83 |
|
@NathanielRN This PR is only touching the base instrumentation package. I believe this is staying in core and not moving to contrib or is the plan to move this as well? |
|
@owais I see that it's also changing |
|
It's just auto-reformat by black. I'll drop these changes when I refactor so nothing to worry about. @NathanielRN |
|
@ocelotl updated to use entry points. Thanks for the tip. |
|
In order to simplify this and use iter points to not hard code knowledge about exporters, I had to temporarily remove support for Datadog exporter. My understanding is that GA does not require this feature to support contrib or 3rd party exporters so we should be good to go. I'll follow up with a separate PR to allow special cases like the Datadog exporter to work with this feature as well. |
ocelotl
left a comment
There was a problem hiding this comment.
Requesting just a typo to be fixed 👍
|
|
||
| if ( | ||
| hasattr(sys, "argv") | ||
| and sys.argv[0].split(os.path.sep)[-1] == "celery" |
There was a problem hiding this comment.
This PR has been open for a while, so in order to move forward I am ok with this as it is right now. Nevertheless, I think we should definitely keep the "core" instrumentation completely separated from the implementation details of any and all of the instrumentation packages. This probably means allowing all the instrumentation packages to be allowed to run a preregistered function or something similar that includes this kind of code.
|
Really excited for this change! I added a PR to this branch to add the ability to set a Custom IDs Generator, would be nice to get these configs all in at once! owais#1 |
| - Fixed boostrap command to correctly install opentelemetry-instrumentation-falcon instead of opentelemetry-instrumentation-flask. ([#1138](https://github.com/open-telemetry/opentelemetry-python/pull/1138)) | ||
| - Added support for `OTEL_EXPORTER` to the `opentelemetry-instrument` command ([#1036](https://github.com/open-telemetry/opentelemetry-python/pull/1036)) |
There was a problem hiding this comment.
We should probably move the PR references to be on a new line to be consistent with the other Changelog messages.
| of the well-known exporter names (see below) or a fully | ||
| qualified Python import path to a span exporter implementation. |
There was a problem hiding this comment.
Does this mean I can set exporter opentelemetry.exporter.jaeger:JaegerSpanExporter?
Sorry for my misunderstanding, but when I look at the code it looks like it will error out if it doesn't match ep.name (where ep is an entry point).
exporters = {
ep.name: ep for ep in iter_entry_points("opentelemetry_exporter")
}
for exporter_name in exporter_names:
entry_point = exporters.get(exporter_name, None)
if not entry_point:
raise RuntimeError(
"Requested exporter not found: {0}".format(exporter_name)
)
So doesn't it have to be otlp?
There was a problem hiding this comment.
You're right. This PR supported what the documentation says but I ended up removing it in order to simplify the implementation. Looks like I missed this piece of documentation when I removed the feature.
| logger.debug("Instrumented %s", entry_point.name) | ||
|
|
||
| except Exception: # pylint: disable=broad-except | ||
| logger.exception("Instrumenting of %s failed", entry_point.name) |
There was a problem hiding this comment.
Should this re-raise the Exception?
There was a problem hiding this comment.
I'm not sure if this case should halt execution of the program and IIRC, any exceptions raised inside sitecustomize are "eaten up" by python by default and the process still continues to work.
There was a problem hiding this comment.
I meant because you only call auto_instrument in line 41 below which is wrapped in another try except block.
So if you re raise it we will get the "Failed to auto initialize opentelemetry" log which will be true in a sense.
| if ( | ||
| hasattr(sys, "argv") | ||
| and sys.argv[0].split(os.path.sep)[-1] == "celery" | ||
| and "worker" in sys.argv |
There was a problem hiding this comment.
Can this be the following? Not sure if it's more performant or less...
| and "worker" in sys.argv | |
| and "worker" in sys.argv[1:] |
There was a problem hiding this comment.
Don't think it matter either way. [1:] probably clarifies the intent a tiny bit more so will make the change.
| from celery.signals import worker_process_init # pylint:disable=E0401 | ||
|
|
||
| @worker_process_init.connect(weak=False) | ||
| def init_celery(*args, **kwargs): | ||
| initialize() |
There was a problem hiding this comment.
This is a sweet catch, thanks for knowing to do something like this!
NathanielRN
left a comment
There was a problem hiding this comment.
Really excited for this change 👍
codeboten
left a comment
There was a problem hiding this comment.
This looks pretty good, just a minor typo to fix and a question about the change in docs.
| Released 2020-10-13 | ||
|
|
||
| - Fixed boostrap command to correctly install opentelemetry-instrumentation-falcon instead of opentelemetry-instrumentation-flask | ||
| - Fixed boostrap command to correctly install opentelemetry-instrumentation-falcon instead of opentelemetry-instrumentation-flask. ([#1138](https://github.com/open-telemetry/opentelemetry-python/pull/1138)) |
There was a problem hiding this comment.
| - Fixed boostrap command to correctly install opentelemetry-instrumentation-falcon instead of opentelemetry-instrumentation-flask. ([#1138](https://github.com/open-telemetry/opentelemetry-python/pull/1138)) | |
| - Fixed bootstrap command to correctly install opentelemetry-instrumentation-falcon instead of opentelemetry-instrumentation-flask. ([#1138](https://github.com/open-telemetry/opentelemetry-python/pull/1138)) |
| :: | ||
|
|
||
| opentelemetry-bootstrap --action=install|requirements | ||
| opentelemetry-instrument -e zipkin,otlp celery -A tasks worker --loglevel=info |
There was a problem hiding this comment.
can you explain the reason behind removing the info about opentelemetry-bootstrap?
There was a problem hiding this comment.
+1, this info is probably important to keep here.
There was a problem hiding this comment.
This is unintentional. Probably caused by a bad rebase. Fixing.
This commit extends the instrument command so it automatically configures tracing with a provider, span processor and exporter. Most of the component used can be customized with env vars or CLI arguments. Details can be found on opentelemetry-instrumentation's README package. Fixes open-telemetry#663
This PR adds support to the
opentelemetry-instrumentcommand to automatically configure a tracer provider and exporter. By default configures the OTLP exporter (like other Otel auto-instrumentations. e.g, Java: https://github.com/open-telemetry/opentelemetry-java-instrumentation#getting-started). It also allows using a different in-built or 3rd party via a CLI argument or env variable.Details can be found on opentelemetry-instrumentation's README package.
Fixes #663
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Checklist: