Skip to content

Commit

Permalink
HPCC-33201 Expose OTel Resource Attribute config options
Browse files Browse the repository at this point in the history
- Defines new Jtrace Resource Attribute config options
- Defaults deploymentEnvironment to development
- Provides sample baremetal config section

Signed-off-by: Rodrigo Pastrana <[email protected]>
  • Loading branch information
rpastrana committed Jan 10, 2025
1 parent 78a4781 commit 5f2dd2b
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 5 deletions.
10 changes: 10 additions & 0 deletions helm/examples/tracing/baremetal-otlp-http-localhost-sample.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Environment>
<Software>
<tracing disabled="false">
<resourceAttributes deploymentEnvironment="development" serviceNamespace="cmakeinstall"/>
<exporters consoleDebug="true" endpoint="http://localhost:4318/v1/traces" type="OTLP-HTTP">
<batch enabled="false" maxQueueSize="4095" scheduledDelayMillis="6001" maxExportBatchSize="511"/>
</exporters>
</tracing>
</Software>
</Environment>
14 changes: 14 additions & 0 deletions helm/hpcc/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1166,6 +1166,20 @@
"items": {
"$ref": "#/definitions/traceExporter"
}
},
"resourceAttributes": {
"type": "object",
"properties": {
"deploymentEnvironment": {
"type": "string",
"description": "Name of the deployment environment (aka deployment tier) such as staging/development/production. "
},
"serviceNamespace": {
"type": "string",
"description": "Identifier used to help distinguish instances of same service"
}
},
"additionalProperties": { "type": ["integer", "string", "boolean"] }
}
},
"additionalProperties": { "type": ["integer", "string", "boolean"] }
Expand Down
2 changes: 2 additions & 0 deletions helm/hpcc/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ global:
tracing:
disabled: false
alwaysCreateTraceIds: true
resourceAttributes: # used to declare OTEL Resource Attribute config values
deploymentEnvironment: development # used to anotate tracing spans' environment identifier (development/production/statiging/etc)

## resource settings for stub components
#stubInstanceResources:
Expand Down
33 changes: 28 additions & 5 deletions system/jlib/jtrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1342,13 +1342,39 @@ std::unique_ptr<opentelemetry::sdk::trace::SpanProcessor> CTraceManager::createP

void CTraceManager::initTracerProviderAndGlobalInternals(const IPropertyTree * traceConfig)
{
/*
Service related resourceAttributes supported by otel:
service.instance.id string The string ID of the service instance.
service.name string Logical name of the service.
service.namespace string A namespace for service.name.
service.version string The version string of the service API or implementation.
*/
opentelemetry::sdk::resource::ResourceAttributes resourceAtts =
{
{"service.name", moduleName.get()},
{"service.version", hpccBuildInfo.buildVersion}
};

std::vector<std::unique_ptr<opentelemetry::sdk::trace::SpanProcessor>> processors;

//By default trace spans to the logs in debug builds - so that developers get used to seeing them.
//Default off for release builds to avoid flooding the logs, and because they are likely to use OTLP
bool enableDefaultLogExporter = isDebugBuild();
if (traceConfig)
{
IPropertyTree * resourceAttributesTree = traceConfig->queryPropTree("resourceAttributes");
if (resourceAttributesTree)
{
const char * depEnv = resourceAttributesTree->queryProp("@deploymentEnvironment");
if (depEnv)
resourceAtts.SetAttribute("deployment.environment", depEnv);

const char * servNS = resourceAttributesTree->queryProp("@serviceNamespace");
if (servNS)
resourceAtts.SetAttribute("service.namespace", servNS);
}

//Administrators can choose to export trace data to a different backend by specifying the exporter type
Owned<IPropertyTreeIterator> iter = traceConfig->getElements("exporters");
ForEach(*iter)
Expand All @@ -1369,11 +1395,6 @@ void CTraceManager::initTracerProviderAndGlobalInternals(const IPropertyTree * t
processors.push_back(opentelemetry::sdk::trace::SimpleSpanProcessorFactory::Create(std::move(exporter)));
}

opentelemetry::sdk::resource::ResourceAttributes resourceAtts =
{
{"service.name", moduleName.get()},
{"service.version", hpccBuildInfo.buildVersion}
};
auto jtraceResource = opentelemetry::sdk::resource::Resource::Create(resourceAtts);

// Default is an always-on sampler.
Expand Down Expand Up @@ -1412,6 +1433,8 @@ void CTraceManager::initTracer(const IPropertyTree * traceConfig)
const char * simulatedGlobalYaml = R"!!(global:
tracing:
disabled: false
resourceAttributes: # used to declare OTEL Resource Attribute config values
deploymentEnvironment: testing
processor:
type: simple
exporter:
Expand Down

0 comments on commit 5f2dd2b

Please sign in to comment.