def _before_flask_request(): environ = flask.request.environ span_name = (flask.request.endpoint or otel_wsgi.get_default_span_name(environ)) token = context.attach( propagators.extract(otel_wsgi.get_header_from_environ, environ)) tracer = trace.get_tracer(__name__, __version__) attributes = otel_wsgi.collect_request_attributes(environ) if flask.request.url_rule: # For 404 that result from no route found, etc, we # don't have a url_rule. attributes["http.route"] = flask.request.url_rule.rule span = tracer.start_span( span_name, kind=trace.SpanKind.SERVER, attributes=attributes, start_time=environ.get(_ENVIRON_STARTTIME_KEY), ) activation = tracer.use_span(span, end_on_exit=True) activation.__enter__() environ[_ENVIRON_ACTIVATION_KEY] = activation environ[_ENVIRON_SPAN_KEY] = span environ[_ENVIRON_TOKEN] = token
def _before_traversal(event): request = event.request environ = request.environ span_name = otel_wsgi.get_default_span_name(environ) enabled = environ.get(_ENVIRON_ENABLED_KEY) if enabled is None: _logger.warning( "Opentelemetry pyramid tween 'opentelemetry.ext.pyramid.trace_tween_factory'" "was not called. Make sure that the tween is included in 'pyramid.tweens' if" "the tween list was created manually") return if not enabled: # Tracing not enabled, return return start_time = environ.get(_ENVIRON_STARTTIME_KEY) token = context.attach( propagators.extract(otel_wsgi.get_header_from_environ, environ)) tracer = trace.get_tracer(__name__, __version__) attributes = otel_wsgi.collect_request_attributes(environ) if request.matched_route: span_name = request.matched_route.pattern attributes["http.route"] = request.matched_route.pattern else: span_name = otel_wsgi.get_default_span_name(environ) span = tracer.start_span( span_name, kind=trace.SpanKind.SERVER, attributes=attributes, start_time=start_time, ) activation = tracer.use_span(span, end_on_exit=True) activation.__enter__() environ[_ENVIRON_ACTIVATION_KEY] = activation environ[_ENVIRON_SPAN_KEY] = span environ[_ENVIRON_TOKEN] = token
def _before_flask_request(): environ = flask_request.environ span_name = flask_request.endpoint or otel_wsgi.get_default_span_name( environ) parent_span = propagators.extract(otel_wsgi.get_header_from_environ, environ) tracer = trace.tracer() span = tracer.start_span( span_name, parent_span, kind=trace.SpanKind.SERVER, start_time=environ.get(_ENVIRON_STARTTIME_KEY), ) activation = tracer.use_span(span, end_on_exit=True) activation.__enter__() environ[_ENVIRON_ACTIVATION_KEY] = activation environ[_ENVIRON_SPAN_KEY] = span otel_wsgi.add_request_attributes(span, environ) if flask_request.url_rule: # For 404 that result from no route found, etc, we don't have a url_rule. span.set_attribute("http.route", flask_request.url_rule.rule)