Skip to content

Commit b6070e2

Browse files
authored
Add request id to trace (#169)
1 parent b2d0cef commit b6070e2

File tree

5 files changed

+37
-1
lines changed

5 files changed

+37
-1
lines changed

include/triton/core/tritonserver.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ struct TRITONSERVER_MetricFamily;
9191
/// }
9292
///
9393
#define TRITONSERVER_API_VERSION_MAJOR 1
94-
#define TRITONSERVER_API_VERSION_MINOR 18
94+
#define TRITONSERVER_API_VERSION_MINOR 19
9595

9696
/// Get the TRITONBACKEND API version supported by the Triton shared
9797
/// library. This value can be compared against the
@@ -857,6 +857,17 @@ TRITONSERVER_DECLSPEC TRITONSERVER_Error*
857857
TRITONSERVER_InferenceTraceModelVersion(
858858
TRITONSERVER_InferenceTrace* trace, int64_t* model_version);
859859

860+
/// Get the request id associated with a trace. The caller does
861+
/// not own the returned string and must not modify or delete it. The
862+
/// lifetime of the returned string extends only as long as 'trace'.
863+
///
864+
/// \param trace The trace.
865+
/// \param request_id Returns the version of the model associated
866+
/// with the trace.
867+
/// \return a TRITONSERVER_Error indicating success or failure.
868+
TRITONSERVER_DECLSPEC TRITONSERVER_Error* TRITONSERVER_InferenceTraceRequestId(
869+
TRITONSERVER_InferenceTrace* trace, const char** request_id);
870+
860871
/// TRITONSERVER_InferenceRequest
861872
///
862873
/// Object representing an inference request. The inference request

src/ensemble_scheduler.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,7 @@ EnsembleContext::InitStep(
957957
if (parent_trace != nullptr) {
958958
irequest->SetTrace(parent_trace->SpawnChildTrace());
959959
irequest->Trace()->SetModelName(irequest->ModelName());
960+
irequest->Trace()->SetRequestId(irequest->Id());
960961
irequest->Trace()->SetModelVersion(irequest->ActualModelVersion());
961962
}
962963
#endif

src/infer_trace.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@ class InferenceTrace {
6161

6262
const std::string& ModelName() const { return model_name_; }
6363
int64_t ModelVersion() const { return model_version_; }
64+
const std::string& RequestId() const { return request_id_; }
6465

6566
void SetModelName(const std::string& n) { model_name_ = n; }
6667
void SetModelVersion(int64_t v) { model_version_ = v; }
68+
void SetRequestId(const std::string& request_id) { request_id_ = request_id; }
6769

6870
// Report trace activity.
6971
void Report(
@@ -117,6 +119,7 @@ class InferenceTrace {
117119

118120
std::string model_name_;
119121
int64_t model_version_;
122+
std::string request_id_;
120123

121124
// Maintain next id statically so that trace id is unique even
122125
// across traces
@@ -137,8 +140,10 @@ class InferenceTraceProxy {
137140
int64_t Id() const { return trace_->Id(); }
138141
int64_t ParentId() const { return trace_->ParentId(); }
139142
const std::string& ModelName() const { return trace_->ModelName(); }
143+
const std::string& RequestId() const { return trace_->RequestId(); }
140144
int64_t ModelVersion() const { return trace_->ModelVersion(); }
141145
void SetModelName(const std::string& n) { trace_->SetModelName(n); }
146+
void SetRequestId(const std::string& n) { trace_->SetRequestId(n); }
142147
void SetModelVersion(int64_t v) { trace_->SetModelVersion(v); }
143148

144149
void Report(

src/tritonserver.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,20 @@ TRITONSERVER_InferenceTraceModelName(
998998
#endif // TRITON_ENABLE_TRACING
999999
}
10001000

1001+
TRITONAPI_DECLSPEC TRITONSERVER_Error*
1002+
TRITONSERVER_InferenceTraceRequestId(
1003+
TRITONSERVER_InferenceTrace* trace, const char** request_id)
1004+
{
1005+
#ifdef TRITON_ENABLE_TRACING
1006+
tc::InferenceTrace* ltrace = reinterpret_cast<tc::InferenceTrace*>(trace);
1007+
*request_id = ltrace->RequestId().c_str();
1008+
return nullptr; // Success
1009+
#else
1010+
return TRITONSERVER_ErrorNew(
1011+
TRITONSERVER_ERROR_UNSUPPORTED, "inference tracing not supported");
1012+
#endif // TRITON_ENABLE_TRACING
1013+
}
1014+
10011015
TRITONAPI_DECLSPEC TRITONSERVER_Error*
10021016
TRITONSERVER_InferenceTraceModelVersion(
10031017
TRITONSERVER_InferenceTrace* trace, int64_t* model_version)
@@ -2907,6 +2921,7 @@ TRITONSERVER_ServerInferAsync(
29072921
tc::InferenceTrace* ltrace = reinterpret_cast<tc::InferenceTrace*>(trace);
29082922
ltrace->SetModelName(lrequest->ModelName());
29092923
ltrace->SetModelVersion(lrequest->ActualModelVersion());
2924+
ltrace->SetRequestId(lrequest->Id());
29102925

29112926
lrequest->SetTrace(std::make_shared<tc::InferenceTraceProxy>(ltrace));
29122927
#else

src/tritonserver_stub.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ TRITONSERVER_InferenceTraceModelVersion()
174174
{
175175
}
176176
TRITONAPI_DECLSPEC void
177+
TRITONSERVER_InferenceTraceRequestId()
178+
{
179+
}
180+
TRITONAPI_DECLSPEC void
177181
TRITONSERVER_InferenceRequestNew()
178182
{
179183
}

0 commit comments

Comments
 (0)