Skip to content

Commit 20aa4ef

Browse files
author
Sam Eagen
committed
Use environment variable NO_MBT_OTEL_CONFIG to skip configuring providers with the MBT
1 parent e2de938 commit 20aa4ef

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

instrumentation/buildtool/+matlab/+buildtool/+plugins/OpenTelemetryPlugin.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@ function runTask(plugin, pluginData)
132132

133133
% Use the same configuration as PADV
134134
function extcontextscope = configureOTel()
135+
136+
% Skip configuration if NO_MBT_OTEL_CONFIG set
137+
if (getenv("NO_MBT_OTEL_CONFIG"))
138+
return;
139+
end
140+
135141
% populate resource attributes
136142
otelservicename = "buildtool";
137143
otelresource = dictionary("service.name", otelservicename);
@@ -174,6 +180,11 @@ function runTask(plugin, pluginData)
174180
% Use the same cleanup as PADV
175181
function cleanupOTel(span)
176182

183+
% Skip cleanup if NO_MBT_OTEL_CONFIG set
184+
if (getenv("NO_MBT_OTEL_CONFIG"))
185+
return;
186+
end
187+
177188
timeout = 5;
178189

179190
% end the input span before cleaning up

test/tbuildtoolplugin.m

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,29 @@ function runningSeveralTasksProducesCorrectMetrics(testCase)
522522
testCase.verifyEqual(metrics(5).name, 'buildtool.tasks.successful');
523523
testCase.verifyEqual(metrics(5).sum.dataPoints.asDouble, 3);
524524
end
525+
526+
function buildToolDoesNotConfigureOTelWhenEnvVariableSet(testCase)
527+
testCase.assumeFalse(isMATLABReleaseOlderThan("R2026a"));
528+
529+
% Restore environment variable
530+
testCase.addTeardown(@()setenv("NO_MBT_OTEL_CONFIG", ""));
531+
532+
% Set environment variable
533+
setenv("NO_MBT_OTEL_CONFIG", "1");
534+
535+
% Create plan with 1 successful task
536+
plan = buildplan();
537+
plan("task") = matlab.buildtool.Task();
538+
539+
% Run build
540+
testCase.BuildRunner.run(plan, "task");
541+
542+
% Get results
543+
results = readJsonResults(testCase);
544+
545+
% Verify results are empty since we never set up any providers
546+
testCase.verifyEmpty(results);
547+
end
525548
end
526549
end
527550

0 commit comments

Comments
 (0)