-
Notifications
You must be signed in to change notification settings - Fork 184
MLAgentTracer Class #3946
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
MLAgentTracer Class #3946
Changes from 13 commits
5949a90
1b78311
ac3dac6
093c0e9
c712e12
b9821af
f57167d
9236e41
6b75c70
7a6e45d
5703c4f
1494166
9fc8b05
8c10cf6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.ml.engine.algorithms.agent.tracing; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| import org.opensearch.ml.common.settings.MLFeatureEnabledSetting; | ||
| import org.opensearch.telemetry.tracing.Span; | ||
| import org.opensearch.telemetry.tracing.Tracer; | ||
|
|
||
| /** | ||
| * Abstract base class for tracing implementations in ML Commons. | ||
| * | ||
| * This class defines the common interface and shared state for all ML tracing logic, | ||
| * such as starting and ending spans. Concrete subclasses (such as {@link MLAgentTracer}) | ||
| * implement tracing for specific ML components or workflows. | ||
| * | ||
| * The intention is to allow for future extension: additional tracers can be created | ||
| * for other ML features (e.g., connector tracing) by extending this class. | ||
| * | ||
| * Each call to {@link #startSpan(String, Map, Span)} returns a {@link Span} object, | ||
| * which acts as a handle to the started span. The {@link Span} object typically contains | ||
| * a unique identifier (span ID) that can be used for logging and debugging. When ending | ||
| * a span, always pass the same {@link Span} object to {@link #endSpan(Span)}. | ||
| */ | ||
| public abstract class AbstractMLTracer { | ||
| protected final Tracer tracer; | ||
| protected final MLFeatureEnabledSetting mlFeatureEnabledSetting; | ||
|
|
||
| /** | ||
| * Constructs a new AbstractMLTracer with the specified tracer and feature settings. | ||
| * | ||
| * @param tracer The underlying tracer implementation to use for span operations. | ||
| * This may be a real tracer or a no-op tracer depending on configuration. | ||
| * @param mlFeatureEnabledSetting The ML feature settings that control tracing behavior. | ||
| * Used to determine if tracing is enabled and which features | ||
| * should be traced. | ||
| */ | ||
| protected AbstractMLTracer(Tracer tracer, MLFeatureEnabledSetting mlFeatureEnabledSetting) { | ||
| this.tracer = tracer; | ||
| this.mlFeatureEnabledSetting = mlFeatureEnabledSetting; | ||
| } | ||
|
|
||
| /** | ||
| * Starts a new span for tracing ML operations. | ||
| * | ||
| * This method creates a new span with the specified name and attributes. The span | ||
| * can be either a root span (when parentSpan is null) or a child span of the | ||
| * specified parent span. The returned Span object should be passed to | ||
| * {@link #endSpan(Span)} when the operation completes. | ||
| * | ||
| * @param name The name of the span. | ||
| * @param attributes A map of key-value pairs to associate with the span. These attributes | ||
| * provide additional context about the operation being traced. May be null | ||
| * or empty if no attributes are needed. | ||
| * @param parentSpan The parent span, or null if this should be a root span. Child spans | ||
| * are nested under their parent spans in the trace hierarchy. | ||
| * @return A Span object representing the started span, or null if tracing is disabled. | ||
| * The returned span should be passed to {@link #endSpan(Span)} when the | ||
| * operation completes. | ||
| */ | ||
| public abstract Span startSpan(String name, Map<String, String> attributes, Span parentSpan); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does the the span has id? thinking if you have multiple start and end, would be helpful the start and end method would return some identifier, so that it would be helpful for future debugging. thinking if you would start multiple span, one the span failed, how do you know which span goes wrong? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes it does, however it is standard practice to use the Span object as the unique identifier There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what do you think of creating an overloaded method for spans without parents: This internally can call the startSpan method with null parent |
||
|
|
||
| /** | ||
| * Ends a previously started span. | ||
| * | ||
| * This method marks the completion of a span and finalizes its timing information. | ||
| * The span will be recorded in the trace with its start time, end time, and any | ||
| * attributes that were set during its lifetime. | ||
| * | ||
| * @param span The span to end. This should be the same Span object that was returned | ||
| * by a previous call to {@link #startSpan(String, Map, Span)}. If null, | ||
| * this method is a no-op. | ||
| */ | ||
| public abstract void endSpan(Span span); | ||
| } | ||
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.
are you expecting other types of the MLTracer other than MLAgentTracer, if so, write the java doc to explain the intension of the the abstract class
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.
fixed