-
Notifications
You must be signed in to change notification settings - Fork 661
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 jinja2 instrumentation #643
Add jinja2 instrumentation #643
Conversation
4cac1a8
to
263f6aa
Compare
263f6aa
to
cf8c885
Compare
try: | ||
return wrapped(*args, **kwargs) | ||
finally: | ||
span.set_attribute("component", "template") |
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.
There is no component
any longer in the semantic conventions.
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.
Is there a link for the background on that change? This has been unclear to me when looking over the code.
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 change was done in open-telemetry/opentelemetry-specification#447, see also open-telemetry/opentelemetry-specification#271. Basically, it was deemed redundant. Previously you could check for component == http
to determine if it is an HTTP span, now you can still check for hasAttribute(http.method)
.
return wrapped(*args, **kwargs) | ||
finally: | ||
span.set_attribute("component", "template") | ||
span.set_attribute("jinja2.template_name", template_name) |
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.
Template engines are widely used across different languages. Have you considered bringing up a spec PR for semantic conventions for templating engines? I think we should aim for cross-language cross-framework consistency here. E.g. maybe templating.engine=jinja2
, templating.template=FILENAME
would be good candidates?
As long as we don't have such conventions, using jinja2
as prefix is however probably the most name-clash-safe way.
Also, please set these attributes already when creating the span, so that they are available to samplers.
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.
Certainly agree about a spec PR and can start a conversation about that as a follow-up from this PR.
4cb1e71
to
8f6790e
Compare
58ad0a7
to
7b1d498
Compare
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.
Looks good overall.
Few comments about some details I found around.
ext/opentelemetry-ext-jinja2/src/opentelemetry/ext/jinja2/__init__.py
Outdated
Show resolved
Hide resolved
ext/opentelemetry-ext-jinja2/src/opentelemetry/ext/jinja2/__init__.py
Outdated
Show resolved
Hide resolved
ext/opentelemetry-ext-jinja2/src/opentelemetry/ext/jinja2/__init__.py
Outdated
Show resolved
Hide resolved
Co-authored-by: Mauricio Vásquez <mauricio@kinvolk.io>
Co-authored-by: Mauricio Vásquez <mauricio@kinvolk.io>
…it__.py Co-authored-by: Mauricio Vásquez <mauricio@kinvolk.io>
…it__.py Co-authored-by: Mauricio Vásquez <mauricio@kinvolk.io>
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.
LGTM, all the comments are simple nits.
I tested by using:
$ cat templates/base.html
Message: {% block content %}{% endblock %}
$ cat templates/template.html
{% extends 'base.html' %}
{% block content %}Hello {{name}}!{% endblock %}
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import (
SimpleExportSpanProcessor,
ConsoleSpanExporter,
)
trace.set_tracer_provider(TracerProvider())
trace.get_tracer_provider().add_span_processor(
SimpleExportSpanProcessor(ConsoleSpanExporter())
)
from jinja2 import Environment, FileSystemLoader
from opentelemetry.ext.jinja2 import Jinja2Instrumentor
Jinja2Instrumentor().instrument()
env = Environment(loader=FileSystemLoader("templates"))
template = env.get_template('template.html')
I see how two spans are generated.
ext/opentelemetry-ext-jinja2/src/opentelemetry/ext/jinja2/__init__.py
Outdated
Show resolved
Hide resolved
Co-authored-by: Mauricio Vásquez <mauricio@kinvolk.io>
Co-authored-by: Mauricio Vásquez <mauricio@kinvolk.io>
Co-authored-by: Mauricio Vásquez <mauricio@kinvolk.io>
Co-authored-by: Mauricio Vásquez <mauricio@kinvolk.io>
Co-authored-by: Mauricio Vásquez <mauricio@kinvolk.io>
Co-authored-by: Mauricio Vásquez <mauricio@kinvolk.io>
Co-authored-by: Mauricio Vásquez <mauricio@kinvolk.io>
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.
LGTM again. Thanks for handling all my comments.
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.
A couple small comments, but otherwise LGTM!
) | ||
|
||
|
||
def _unwrap(obj, attr): |
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.
an aside, but unwrapping looks to be everywhere now. We might want to see what we can do to consolidate: #667
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.
Agreed, will comment on the issue and we can refactor the unwrapping code accordingly.
a30ac27
to
0c2c269
Compare
Migrating the jinja2 plugin forked from ddtracepy. Co-authored-by: Mauricio Vásquez <mauricio@kinvolk.io>
* feat(plugin-http): add/modify attributes closes open-telemetry#373, open-telemetry#394 Signed-off-by: Olivier Albertini <olivier.albertini@montreal.ca> * fix: change remotePort to localPort refactor: remove useless checks test: add assertions Signed-off-by: Olivier Albertini <olivier.albertini@montreal.ca> * test(plugin-https): sync with http plugin Signed-off-by: Olivier Albertini <olivier.albertini@montreal.ca> Co-authored-by: Mayur Kale <mayurkale@google.com>
Fixes #631