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

Automatic exporter/provider setup for opentelemetry-instrument command. #1036

Merged
merged 1 commit into from
Nov 20, 2020

Conversation

owais
Copy link
Contributor

@owais owais commented Aug 23, 2020

This PR adds support to the opentelemetry-instrument command 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.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

How Has This Been Tested?

  • Ships with automated tests
  • Tested with a demo app

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@owais owais requested a review from a team August 23, 2020 23:16
@owais owais force-pushed the otlp-env-config branch 2 times, most recently from 1568630 to 05a1fed Compare August 29, 2020 15:05
@owais owais changed the title POC: actual auto-instrumentation Automatic exporter/provider setup for opentelemetry-instrument command. Aug 29, 2020
@owais owais force-pushed the otlp-env-config branch 2 times, most recently from 53a5233 to 0ec2526 Compare August 29, 2020 15:10
owais added a commit to owais/opentelemetry-python that referenced this pull request Aug 29, 2020
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
owais added a commit to owais/opentelemetry-python that referenced this pull request Aug 29, 2020
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
owais added a commit to owais/opentelemetry-python that referenced this pull request Aug 29, 2020
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
owais added a commit to owais/opentelemetry-python that referenced this pull request Aug 29, 2020
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
owais added a commit to owais/opentelemetry-python that referenced this pull request Aug 29, 2020
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
owais added a commit to owais/opentelemetry-python that referenced this pull request Aug 29, 2020
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
owais added a commit to owais/opentelemetry-python that referenced this pull request Aug 29, 2020
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
owais added a commit to owais/opentelemetry-python that referenced this pull request Aug 29, 2020
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
owais added a commit to owais/opentelemetry-python that referenced this pull request Aug 29, 2020
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
owais added a commit to owais/opentelemetry-python that referenced this pull request Aug 29, 2020
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
owais added a commit to owais/opentelemetry-python that referenced this pull request Aug 29, 2020
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
owais added a commit to owais/opentelemetry-python that referenced this pull request Aug 29, 2020
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
@owais owais force-pushed the otlp-env-config branch 4 times, most recently from 762fa1b to 9162fff Compare November 10, 2020 13:49
Copy link
Contributor

@ocelotl ocelotl left a comment

Choose a reason for hiding this comment

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

Requesting just a typo to be fixed 👍

opentelemetry-instrumentation/README.rst Outdated Show resolved Hide resolved

if (
hasattr(sys, "argv")
and sys.argv[0].split(os.path.sep)[-1] == "celery"
Copy link
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

@ocelotl ocelotl left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @owais!

@NathanielRN
Copy link
Contributor

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

@owais owais force-pushed the otlp-env-config branch 2 times, most recently from 2482d9f to 0331351 Compare November 18, 2020 17:45
Comment on lines 9 to 10
- 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))
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably move the PR references to be on a new line to be consistent with the other Changelog messages.

Comment on lines 40 to 41
of the well-known exporter names (see below) or a fully
qualified Python import path to a span exporter implementation.
Copy link
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this re-raise the Exception?

Copy link
Contributor Author

@owais owais Nov 18, 2020

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, makes sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

if (
hasattr(sys, "argv")
and sys.argv[0].split(os.path.sep)[-1] == "celery"
and "worker" in sys.argv
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be the following? Not sure if it's more performant or less...

Suggested change
and "worker" in sys.argv
and "worker" in sys.argv[1:]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't think it matter either way. [1:] probably clarifies the intent a tiny bit more so will make the change.

Comment on lines +51 to +55
from celery.signals import worker_process_init # pylint:disable=E0401

@worker_process_init.connect(weak=False)
def init_celery(*args, **kwargs):
initialize()
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 a sweet catch, thanks for knowing to do something like this!

@owais owais force-pushed the otlp-env-config branch 2 times, most recently from 6513835 to c43f3c5 Compare November 18, 2020 17:56
Copy link
Contributor

@NathanielRN NathanielRN left a comment

Choose a reason for hiding this comment

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

Really excited for this change 👍

Copy link
Contributor

@codeboten codeboten left a comment

Choose a reason for hiding this comment

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

This looks pretty good, just a minor typo to fix and a question about the change in docs.

## Version 0.14b0

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))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- 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
Copy link
Contributor

Choose a reason for hiding this comment

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

can you explain the reason behind removing the info about opentelemetry-bootstrap?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1, this info is probably important to keep here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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
Copy link
Contributor

@codeboten codeboten left a comment

Choose a reason for hiding this comment

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

Thanks for fixing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:required-for-ga To be resolved before GA release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement a mechanism to configure exporters with autoinstrumentation command
5 participants