Slackbot
08/14/2023, 6:58 PMFernando Camargo
08/14/2023, 11:36 PMdef new_tracing_span(
name: str, attributes: trace.types.Attributes = None
) -> Iterator[trace.Span]:
return (
trace.get_tracer_provider()
.get_tracer(__name__)
.start_as_current_span(name, attributes=attributes)
)
with new_tracing_span("preprocessing_fn"):
# ...
Maybe I would need the same tracer instance? From reading the code, it doesn't seem like I have access to it.Fernando Camargo
08/15/2023, 10:03 PMdef new_tracing_span(
name: str, attributes: trace.types.Attributes = None
) -> Iterator[trace.Span]:
tracer = BentoMLContainer.tracer_provider.get().get_tracer(
otel_asgi.__name__,
otel_asgi.__version__,
)
return tracer.start_as_current_span(
name,
context=context.get_current(),
kind=trace.SpanKind.INTERNAL,
attributes=attributes,
)Jian Shen Yap
08/16/2023, 10:34 AMFernando Camargo
08/16/2023, 8:22 PMNone (the usual case), we fetch the page. We then preprocess this HTML to feed it into our MarkupLM model (which will extract text and XPaths and then tokenize). For last, I invoke my model. So, I want to know how longs it's taking to fetch pages and preprocess them. That's why I'm registering spans for each of them.Amit Gelber
03/25/2024, 7:15 PMFernando Camargo
03/26/2024, 4:04 PMfrom bentoml._internal.configuration.containers import BentoMLContainer
from opentelemetry import context, trace
from opentelemetry.instrumentation import asgi as otel_asgi
def new_tracing_span(
name: str, attributes: trace.types.Attributes = None
) -> Iterator[trace.Span]:
tracer = BentoMLContainer.tracer_provider.get().get_tracer(
otel_asgi.__name__,
otel_asgi.__version__,
)
return tracer.start_as_current_span(
name,
context=context.get_current(),
kind=trace.SpanKind.INTERNAL,
attributes=attributes,
)
Not ideal, as I'm using internal modules from BentoML, but it works, @Amit GelberAmit Gelber
03/26/2024, 4:30 PMFernando Camargo
03/26/2024, 4:49 PMwith new_tracing_span("/predict preprocessing"):
# Code for preprocessing
with new_tracing_span("/predict runner"):
probas = await runner(batch)
The idea is that I have one parent trace for the /predict and then I want to break down into smaller spans.Fernando Camargo
03/26/2024, 4:51 PMdef register_input(api_input: ApiInput):
span = trace.get_current_span()
for i, instance in enumerate(api_input.instances):
span.set_attribute("input.instances[%d].url" % i, instance.url)
span.set_attribute("input.parameters.threshold", api_input.parameters.threshold)
def register_output(api_output: ApiOutput):
span = trace.get_current_span()
for i, prediction in enumerate(api_output.predictions):
span.set_attribute("output.predictions[%d].url" % i, prediction.url)
for j, tag in enumerate(prediction.tags):
span.set_attribute(
"output.predictions[%d].tags[%d].label" % (i, j), tag.label
)
span.set_attribute(
"output.predictions[%d].tags[%d].proba" % (i, j), tag.proba
)
I invoke them in the beginning and the end of my service function.Amit Gelber
03/26/2024, 7:09 PMwith tracer.start_as_current_span("Inference") as span:
that's it.
I wish if someone from BentoML could clarify thisJian Shen Yap
03/27/2024, 7:55 AMAmit Gelber
03/28/2024, 10:27 AMAmit Gelber
03/30/2024, 10:32 AMJian Shen Yap
03/31/2024, 2:29 PMAmit Gelber
04/01/2024, 8:29 AMJian Shen Yap
04/01/2024, 8:31 AM