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

Introduce Context.suppress_instrumentation #181

Merged
merged 3 commits into from
Sep 27, 2019
Merged

Introduce Context.suppress_instrumentation #181

merged 3 commits into from
Sep 27, 2019

Conversation

reyang
Copy link
Member

@reyang reyang commented Sep 27, 2019

Added Context.suppress_instrumentation flag, which can be used for the following scenarios:

  1. avoid instrumentation while running inside exporter.
  2. suppress certain call path to avoid excessive/unwanted data.

@@ -50,8 +51,8 @@ def enable(tracer):

@functools.wraps(wrapped)
def instrumented_request(self, method, url, *args, **kwargs):
# TODO: Check if we are in an exporter, cf. OpenCensus
# execution_context.is_exporter()
if Context.is_exporter: # Check if we are in an exporter
Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe we can generalize this concept into a "terminal span" as @a-feld mentioned. Save this for the post alpha v0.1 work.

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed to suppress_instrumentation as suggested by @Oberon00.

@reyang
Copy link
Member Author

reyang commented Sep 27, 2019

@mauriciovasquezbernal FYI related to #153.

@Oberon00
Copy link
Member

Oberon00 commented Sep 27, 2019

Context.is_exporter sounds strange, as if it checks whether the context is an exporter, which wouldn't make sense. Thus I suggest Context.is_exporter_active or maybe Context.is_exporting. Regarding your comment, why not name it Context.suppress_instrumentation?

@mauriciovasquezbernal
Copy link
Member

It'd be really nice to have a commit/PR description so one can understand what it is about without having to go to the code.

@Oberon00 Oberon00 changed the title Avoid requests hijack while running inside an exporter Add Context.is_exporter to avoid instrumentating exporter HTTP requests Sep 27, 2019
@Oberon00 Oberon00 changed the title Add Context.is_exporter to avoid instrumentating exporter HTTP requests Add Context.is_exporter to avoid instrumenting exporter HTTP requests Sep 27, 2019
@Oberon00 Oberon00 changed the title Add Context.is_exporter to avoid instrumenting exporter HTTP requests Add Context.is_exporter to avoid instrumenting exporter's HTTP requests Sep 27, 2019
@Oberon00
Copy link
Member

Please update to also cover batch exporter (#153)

@reyang reyang changed the title Add Context.is_exporter to avoid instrumenting exporter's HTTP requests Introduce Context.suppress_instrumentation Sep 27, 2019
@reyang reyang added this to the Alpha Release milestone Sep 27, 2019
self.span_exporter.export((span,))
# pylint: disable=broad-except
except Exception as exc:
logger.warning("Exception while exporting data: %s", exc)
finally:
Copy link
Member Author

Choose a reason for hiding this comment

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

Minor: I was a bit struggling whether to put this in finally statement or not.

suppress_instrumentation = Context.suppress_instrumentation
try:
    Context.suppress_instrumentation = True
    self.span_exporter.export((span,))
# pylint: disable=broad-except
except Exception as exc:
    logger.warning("Exception while exporting data: %s", exc)
Context.suppress_instrumentation = suppress_instrumentation

This looks nicer (symmetric), however if there is uncaught exception, or later someone added a return in the try statement, the context could get wrong.

Copy link
Member Author

Choose a reason for hiding this comment

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

And introducing a context manager seems to be an overkill here.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with the finally here, but also think a context manager in context would make sense.

with Context.set('suppress_instrumentation', True):
    # do stuff that shouldn't be instrumented

This would also let you use the set/reset token, which you can't access here since Context doesn't expose the ContextVars it uses under the hood.

Copy link
Member

@c24t c24t left a comment

Choose a reason for hiding this comment

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

LGTM. You might consider making suppress_instrumentation a first-class citizen since we're likely to use it elsewhere. I don't think context should know about instrumentation, but maybe in opentelemetry-api.

@reyang
Copy link
Member Author

reyang commented Sep 27, 2019

Created #183 and #184 to follow up post Alpha v0.1.

@reyang reyang merged commit 74f2cec into master Sep 27, 2019
@reyang reyang deleted the is_exporter branch September 27, 2019 23:57
hectorhdzg added a commit to hectorhdzg/opentelemetry-python that referenced this pull request Oct 21, 2019
for start_time and end_time

Make lint happy

Addressing comments

Addressing comments

Allowing 0 as start and end time

Fix lint issues

Metrics API RFC 0003 cont'd (open-telemetry#136)

* Create functions

Comments for Meter

More comments

Add more comments

Fix typos

* fix lint

* Fix lint

* fix typing

* Remove options, constructors, seperate labels

* Consistent naming for float and int

* Abstract time series

* Use ABC

* Fix typo

* Fix docs

* seperate measure classes

* Add examples

* fix lint

* Update to RFC 0003

* Add spancontext, measurebatch

* Fix docs

* Fix comments

* fix lint

* fix lint

* fix lint

* skip examples

* white space

* fix spacing

* fix imports

* fix imports

* LabelValues to str

* Black formatting

* fix isort

* Remove aggregation

* Fix names

* Remove aggregation from docs

* Fix lint

* metric changes

* Typing

* Fix lint

* Fix lint

* Add space

* Fix lint

* fix comments

* address comments

* fix comments

Adding a working propagator, adding to integrations and example (open-telemetry#137)

Adding a full, end-to-end example of propagation at work in the
example application, including a test.

Adding the use of propagators into the integrations.

Metrics API RFC 0009 (open-telemetry#140)

* Create functions

Comments for Meter

More comments

Add more comments

Fix typos

* fix lint

* Fix lint

* fix typing

* Remove options, constructors, seperate labels

* Consistent naming for float and int

* Abstract time series

* Use ABC

* Fix typo

* Fix docs

* seperate measure classes

* Add examples

* fix lint

* Update to RFC 0003

* Add spancontext, measurebatch

* Fix docs

* Fix comments

* fix lint

* fix lint

* fix lint

* skip examples

* white space

* fix spacing

* fix imports

* fix imports

* LabelValues to str

* Black formatting

* fix isort

* Remove aggregation

* Fix names

* Remove aggregation from docs

* Fix lint

* metric changes

* Typing

* Fix lint

* Fix lint

* Add space

* Fix lint

* fix comments

* handle, recordbatch

* docs

* Update recordbatch

* black

* Fix typo

* remove ValueType

* fix lint

Console exporter (open-telemetry#156)

Make use_span more flexible (closes open-telemetry#147). (open-telemetry#154)

Co-Authored-By: Reiley Yang <[email protected]>
Co-Authored-By: Chris Kleinknecht <[email protected]>

WSGI fixes (open-telemetry#148)

Fix http.url.
Don't delay calling wrapped app.

Skeleton for azure monitor exporters (open-telemetry#151)

Add link to docs to README (open-telemetry#170)

Move example app to the examples folder (open-telemetry#172)

WSGI: Fix port 80 always appended in http.host (open-telemetry#173)

Build and host docs via github action (open-telemetry#167)

Add missing license boilerplate to a few files (open-telemetry#176)

sdk/trace/exporters: add batch span processor exporter (open-telemetry#153)

The exporters specification states that two built-in span processors should be
implemented, the simple processor span and the batch processor span.

This commit implements the latter, it is mainly based on the opentelemetry/java
one.

The algorithm implements the following logic:
- a condition variable is used to notify the worker thread in case the queue
is half full, so that exporting can start before the queue gets full and spans
are dropped.
- export is called each schedule_delay_millis if there is a least one new span
to export.
- when the processor is shutdown all remaining spans are exported.

Implementing W3C TraceContext (fixes open-telemetry#116) (open-telemetry#180)

* Implementing TraceContext (fixes open-telemetry#116)

This introduces a w3c TraceContext propagator, primarily inspired by opencensus.

fix time conversion bug (open-telemetry#182)

Introduce Context.suppress_instrumentation (open-telemetry#181)

Metrics Implementation (open-telemetry#160)

* Create functions

Comments for Meter

More comments

Add more comments

Fix typos

* fix lint

* Fix lint

* fix typing

* Remove options, constructors, seperate labels

* Consistent naming for float and int

* Abstract time series

* Use ABC

* Fix typo

* Fix docs

* seperate measure classes

* Add examples

* fix lint

* Update to RFC 0003

* Add spancontext, measurebatch

* Fix docs

* Fix comments

* fix lint

* fix lint

* fix lint

* skip examples

* white space

* fix spacing

* fix imports

* fix imports

* LabelValues to str

* Black formatting

* fix isort

* Remove aggregation

* Fix names

* Remove aggregation from docs

* Fix lint

* metric changes

* Typing

* Fix lint

* Fix lint

* Add space

* Fix lint

* fix comments

* handle, recordbatch

* docs

* Update recordbatch

* black

* Fix typo

* remove ValueType

* fix lint

* sdk

* metrics

* example

* counter

* Tests

* Address comments

* ADd tests

* Fix typing and examples

* black

* fix lint

* remove override

* Fix tests

* mypy

* fix lint

* fix type

* fix typing

* fix tests

* isort

* isort

* isort

* isort

* noop

* lint

* lint

* fix tuple typing

* fix type

* black

* address comments

* fix type

* fix lint

* remove imports

* default tests

* fix lint

* usse sequence

* remove ellipses

* remove ellipses

* black

* Fix typo

* fix example

* fix type

* fix type

* address comments

Implement Azure Monitor Exporter (open-telemetry#175)

Span add override parameters for start_time and end_time (open-telemetry#179)

CONTRIBUTING.md: Fix clone URL (open-telemetry#177)

Add B3 exporter to alpha release table (open-telemetry#164)

Update README for alpha release (open-telemetry#189)

Update Contributing.md doc (open-telemetry#194)

Add **simple** client/server examples (open-telemetry#191)

Remove unused dev-requirements.txt (open-telemetry#200)

The requirements are contained in tox.ini now.

Fx bug in BoundedList for Python 3.4 and add tests (open-telemetry#199)

* fix bug in BoundedList for python 3.4 and add tests

collections.deque.copy() was introduced in python 3.5, this commit changes
that by the deque constructor and adds some tests to BoundedList and BoundedDict
to avoid similar problems in the future.

Also, improve docstrings of BoundedList and BoundedDict classes

Move util.time_ns to API. (open-telemetry#205)

Add Jaeger exporter (open-telemetry#174)

This adds a Jeager exporter for OpenTelemetry.  This exporter is based
on https://github.com/census-instrumentation/opencensus-python/tree/master/contrib/opencensus-ext-jaeger.

The exporter uses thrift and can be configured to send data to the agent and
also to a remote collector.

There is a long discussion going on about how to include generated files
in the repo, so for now just put them here.

Add code coverage

Revert latest commit

Fix some "errors" found by mypy. (open-telemetry#204)

Fix some errors found by mypy (split from open-telemetry#201).

Update README for new milestones (open-telemetry#218)

Refactor current span handling for newly created spans. (open-telemetry#198)

1. Make Tracer.start_span() simply create and start the Span,
   without setting it as the current instance.
2. Add an extra Tracer.start_as_current_span() to create the
   Span and set it as the current instance automatically.

Co-Authored-By: Chris Kleinknecht <[email protected]>

Add set_status to Span (open-telemetry#213)

Initial commit

Initial version
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.

5 participants