mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-07-31 14:11:50 +08:00
Add callback for direct instrument
This commit is contained in:
@ -208,3 +208,32 @@ class TestProgrammaticCustomSpanName(
|
||||
span_list = self.memory_exporter.get_finished_spans()
|
||||
self.assertEqual(len(span_list), 1)
|
||||
self.assertEqual(span_list[0].name, "flask-custom-span-name")
|
||||
|
||||
|
||||
class TestProgrammaticCustomSpanNameCallbackWithoutApp(
|
||||
InstrumentationTest, TestBase, WsgiTestBase
|
||||
):
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
|
||||
def custom_span_name():
|
||||
return "instrument-without-app"
|
||||
|
||||
FlaskInstrumentor().instrument(name_callback=custom_span_name)
|
||||
from flask import Flask
|
||||
|
||||
self.app = Flask(__name__)
|
||||
|
||||
self._common_initialization()
|
||||
|
||||
def tearDown(self):
|
||||
super().tearDown()
|
||||
with self.disable_logging():
|
||||
FlaskInstrumentor().uninstrument()
|
||||
|
||||
def test_custom_span_name(self):
|
||||
self.client.get("/hello/123")
|
||||
|
||||
span_list = self.memory_exporter.get_finished_spans()
|
||||
self.assertEqual(len(span_list), 1)
|
||||
self.assertEqual(span_list[0].name, "instrument-without-app")
|
||||
|
Reference in New Issue
Block a user