Skip to content

feat(options): add option to disable the Server-Timing header - #921

Open
arjun-rajappa wants to merge 1 commit into
mainfrom
feat/disable-server-timing-option
Open

arjun-rajappa wants to merge 1 commit into
mainfrom
feat/disable-server-timing-option

Conversation

@arjun-rajappa

Copy link
Copy Markdown
Contributor

Why

Some users do not want the Instana Server-Timing header (intid;desc=<trace id>) added to their responses and outgoing requests. This adds a documented switch to turn it off, following the same configuration precedence as the other tracing options.

What

  • Add disable_server_timing to BaseOptions (default False). Precedence: INSTANA_TRACING_DISABLE_SERVER_TIMING > INSTANA_CONFIG_PATH YAML (tracing.global.disable-server-timing) > agent config > default. The agent config is applied in StandardOptions._apply_agent_disable_server_timing().
  • Add get_disable_server_timing_from_yaml() in util/config.py. It supports the deprecated com.instana.tracing root and tolerates an empty tracing: section.
  • Add BasePropagator.is_server_timing_disabled(). It reads the flag on every call, so runtime agent-config changes are honoured. It falls back to enabled and logs at debug level if the agent is unavailable.
  • HTTPPropagator, TextPropagator, BinaryPropagator and lambda_inst.py skip the header when the flag is set. The Lambda status-code handling is unchanged. The header logic moved into an add_server_timing_header() helper.
  • In TextPropagator and BinaryPropagator, build the headers once and write them per carrier type, instead of repeating if server_timing: in every branch. Injected headers and their order are unchanged.
  • Tests:
    • Options, YAML config reader and is_server_timing_disabled().
    • HTTP, binary and new text propagator tests.
    • New tests/instrumentation/aws/test_lambda_inst.py with a mocked agent.

Signed-off-by: Arjun Rajappa <arjun.rajappa@ibm.com>
@arjun-rajappa
arjun-rajappa requested a review from a team as a code owner November 9, 2026 05:53

@CagriYonca CagriYonca left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a couple of comments. What do you think?

from instana.singletons import env_is_aws_lambda, get_agent, get_tracer
from instana.util.ids import define_server_timing

def add_server_timing_header(result: Dict[str, Any], trace_id: int) -> None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use dict instead of Dict? And avoid using Any if possible

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with @CagriYonca.
Since Python 3.9, we can use the built-ins dict, list, and tuple instead of the imported Dict, List, and Tuple from the typing module.
I don't like the indiscriminate use of Any, but Bob does. If you know the possible types or classes for the dictionary values, please list them.

Comment thread src/instana/options.py
get_disable_trace_configurations_from_env,
get_disable_trace_configurations_from_local,
get_disable_trace_configurations_from_yaml,
get_disable_server_timing_from_yaml,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this above get_disable_trace_configurations_* to keep the list alphabetical.

Comment thread src/instana/options.py
Apply tracing.global.disable-server-timing from agent config (lowest
priority: the environment variable and the YAML file take precedence).
"""
global_config = tracing.get("global")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add this parameter to the configuration test yaml files?

span_id = format_span_id(span_context.span_id).encode()
level = str(span_context.level).encode()
server_timing = define_server_timing(span_context.trace_id).encode()
server_timing = (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If server_timing is not used anywhere else, can we change this and move it to line 67?

if not self.is_server_timing_disabled():
    headers.append((self.HEADER_SERVER_TIMING, define_server_timing(span_context.trace_id).encode()))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do prefer the way @arjun-rajappa proposed here. With that, we have a common place to set all necessary values, even if used just once.

trace_id = format_span_id(span_context.trace_id)
span_id = format_span_id(span_context.span_id)
server_timing = define_server_timing(span_context.trace_id).encode()
server_timing = (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as this.


def test_exception_defaults_to_enabled(self) -> None:
with patch("instana.singletons.get_agent", side_effect=RuntimeError("boom")):
assert BasePropagator.is_server_timing_disabled() is False

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we check whether the debug log is emitted by caplog or not?

synthetic=False,
)

def test_dict(self, trace_id: int, span_id: int, hex_trace_id: str) -> None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use self-explainer test function names, such as test_binary_inject_dict_server_timing_disabled()?

Same for others, too.

@pvital pvital left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, it looks good to me - just a few comments based on @CagriYonca's review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants