Skip to content
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

Add Native Writer #13071

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions ddtrace/_trace/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
from ddtrace.internal.utils.formats import format_trace_id
from ddtrace.internal.utils.http import verify_url
from ddtrace.internal.writer import AgentResponse
from ddtrace.internal.writer import AgentWriter
from ddtrace.internal.writer import NativeWriter
from ddtrace.internal.writer import LogWriter
from ddtrace.internal.writer import TraceWriter
from ddtrace.settings._config import Config
Expand Down Expand Up @@ -241,13 +241,11 @@ def __init__(self) -> None:
if self._use_log_writer():
writer: TraceWriter = LogWriter()
else:
writer = AgentWriter(
writer = NativeWriter(
agent_url=self._agent_url,
dogstatsd=get_dogstatsd_client(self._dogstatsd_url),
sync_mode=self._use_sync_mode(),
headers={"Datadog-Client-Computed-Stats": "yes"}
if (self._compute_stats or asm_config._apm_opt_out)
else {},
compute_stats_enabled=self._compute_stats,
report_metrics=not asm_config._apm_opt_out,
response_callback=self._agent_response_callback,
)
Expand Down Expand Up @@ -434,7 +432,7 @@ def configure(
if compute_stats_enabled is not None:
self._compute_stats = compute_stats_enabled

if isinstance(self._writer, AgentWriter):
if isinstance(self._writer, NativeWriter):
if appsec_enabled:
self._writer._api_version = "v0.4"
self._writer.dogstatsd = get_dogstatsd_client(self._dogstatsd_url)
Expand Down Expand Up @@ -821,7 +819,7 @@ def current_span(self) -> Optional[Span]:
@property
def agent_trace_url(self) -> Optional[str]:
"""Trace agent url"""
if isinstance(self._writer, AgentWriter):
if isinstance(self._writer, NativeWriter):
return self._writer.agent_url

return None
Expand Down
3 changes: 2 additions & 1 deletion ddtrace/internal/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from ddtrace.internal.utils.cache import callonce
from ddtrace.internal.writer import AgentWriter
from ddtrace.internal.writer import LogWriter
from ddtrace.internal.writer import NativeWriter
from ddtrace.settings.asm import config as asm_config

from .logger import get_logger
Expand Down Expand Up @@ -57,7 +58,7 @@ def collect(tracer):
if isinstance(tracer._writer, LogWriter):
agent_url = "AGENTLESS"
agent_error = None
elif isinstance(tracer._writer, AgentWriter):
elif isinstance(tracer._writer, AgentWriter) or isinstance(trace._writer, NativeWriter):
writer = tracer._writer
agent_url = writer.agent_url
try:
Expand Down
12 changes: 12 additions & 0 deletions ddtrace/internal/native/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@

from ._native import DDSketch # noqa: F401
from ._native import PyConfigurator
from ._native import TraceExporter, TraceExporterBuilder

# Exceptions used by the TraceExporter
from ._native import (
AgentError,
BuilderError,
DeserializationError,
IoError,
NetworkError,
RequestError,
SerializationError,
)


def get_configuration_from_disk(
Expand Down
230 changes: 230 additions & 0 deletions ddtrace/internal/native/_native.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -20,36 +20,266 @@ class PyConfigurator:
:param debug_logs: A boolean indicating whether debug logs should be enabled.
"""
...

def set_local_file_override(self, file: str) -> None:
"""
Overrides the local file path for the configuration. Should not be used outside of tests.
:param file: The path to the local file to override.
"""
...

def set_managed_file_override(self, file: str) -> None:
"""
Overrides the managed file path for the configuration. Should not be used outside of tests.
:param file: The path to the managed file to override.
"""
...

def get_configuration(self) -> List[Dict[str, str]]:
"""
Retrieve the on-disk configuration.
:return: A list of dictionaries containing the configuration:
[{"source": ..., "key": ..., "value": ..., "config_id": ...}]
"""
...

@property
def local_stable_config_type(self) -> str:
"""
Retrieve the local stable configuration type.
:return: A string representing the local stable configuration type.
"""
...

@property
def fleet_stable_config_type(self) -> str:
"""
Retrieve the fleet stable configuration type.
:return: A string representing the fleet stable configuration type.
"""
...

class TraceExporter:
"""
TraceExporter is a class responsible for exporting traces to the Agent.
"""

def __init__(self):
"""
Initialize a TraceExporter.
"""
...

def send(self, data: bytes, trace_count: int) -> str:
"""
Send a trace payload to the Agent.
:param data: The msgpack encoded trace payload to send.
:param trace_count: The number of traces in the data payload.
"""
...

def shutdown(self, timeout_ns: int) -> None:
"""
Shutdown the TraceExporter, releasing any resources and ensuring all pending traces are sent.
This method should be called before the application exits to ensure proper cleanup.
:param timeout_ns: The maximum time to wait for shutdown in nanoseconds.
"""
...

class TraceExporterBuilder:
"""
TraceExporterBuilder is a class responsible for building a TraceExporter.
"""

def __init__(self):
"""
Initialize a TraceExporterBuilder.
"""
...

def set_hostname(self, hostname: str) -> TraceExporterBuilder:
"""
Set the hostname of the TraceExporter.
:param hostname: The hostname to set for the TraceExporter.
"""
...

def set_url(self, url: str) -> TraceExporterBuilder:
"""
Set the agent url of the TraceExporter.
:param url: The URL of the agent to send traces to.
"""
...

def set_dogstatsd_url(self, url: str) -> TraceExporterBuilder:
"""
Set the DogStatsD URL of the TraceExporter.
:param url: The URL of the DogStatsD endpoint.
"""
...

def set_env(self, env: str) -> TraceExporterBuilder:
"""
Set the env of the TraceExporter.
:param env: The environment name (e.g., 'prod', 'staging', 'dev').
"""
...

def set_app_version(self, version: str) -> TraceExporterBuilder:
"""
Set the app version of the TraceExporter.
:param version: The version string of the application.
"""
...

def set_git_commit_sha(self, git_commit_sha: str) -> TraceExporterBuilder:
"""
Set the git commit sha of the TraceExporter.
:param git_commit_sha: The git commit SHA of the current code version.
"""
...

def set_tracer_version(self, version: str) -> TraceExporterBuilder:
"""
Set the tracer version of the TraceExporter.
:param version: The version string of the tracer.
"""
...

def set_language(self, language: str) -> TraceExporterBuilder:
"""
Set the language of the TraceExporter.
:param language: The programming language being traced (e.g., 'python').
"""
...

def set_language_version(self, version: str) -> TraceExporterBuilder:
"""
Set the language version of the TraceExporter.
:param version: The version string of the programming language.
"""
...

def set_language_interpreter(self, interpreter: str) -> TraceExporterBuilder:
"""
Set the language interpreter of the TraceExporter.
:param vendor: The language interpreter.
"""
...

def set_language_interpreter_vendor(self, vendor: str) -> TraceExporterBuilder:
"""
Set the language interpreter vendor of the TraceExporter.
:param vendor: The vendor of the language interpreter.
"""
...

def set_test_session_token(self, token: str) -> TraceExporterBuilder:
"""
Set the test session token for the TraceExporter.
:param token: The test session token to use for authentication.
"""
...

def set_input_format(self, format: str) -> TraceExporterBuilder:
"""
Set the input format for the trace data.
:param format: The format to use for input traces (supported values are "v0.4" and "v0.5").
:raises ValueError: If format is not a supported value.
"""
...

def set_output_format(self, format: str) -> TraceExporterBuilder:
"""
Set the output format for the trace data.
:param format: The format to use for output traces (supported values are "v0.4" and "v0.5").
:raises ValueError: If format is not a supported value.
"""
...

def set_client_computed_top_level(self) -> TraceExporterBuilder:
"""
Set the header indicating the tracer has computed the top-level tag
"""
...

def enable_stats(self, bucket_size_ns: int) -> TraceExporterBuilder:
"""
Enable stats computation in the TraceExporter
:param bucket_size_ns: The size of stats bucket in nanoseconds.
"""
...

def enable_telemetry(
self,
heartbeat: int,
runtime_id: str,
) -> TraceExporterBuilder:
"""
Enable stats computation in the TraceExporter
:param bucket_size_ns: The size of stats bucket in nanoseconds.
"""
...

def build(self) -> TraceExporter:
"""
Build and return a TraceExporter instance with the configured settings.
This method consumes the builder, so it cannot be used again after calling build.
:return: A configured TraceExporter instance.
:raises ValueError: If the builder has already been consumed or if required settings are missing.
"""
...

class AgentError(Exception):
"""
Raised when there is an error in agent response processing.
"""

...

class BuilderError(Exception):
"""
Raised when there is an error in the TraceExporterBuilder configuration.
"""

...

class DeserializationError(Exception):
"""
Raised when there is an error deserializing trace payload.
"""

...

class IoError(Exception):
"""
Raised when there is an I/O error during trace processing.
"""

...

class NetworkError(Exception):
"""
Raised when there is a network-related error during trace processing.
"""

...

class RequestError(Exception):
"""
Raised when the agent responds with an error code.
"""

...

class SerializationError(Exception):
"""
Raised when there is an error serializing trace payload.
"""

...

class EncodingNotSupportedError(Exception):
"""
Raised when the agent return a 404 or 415 error code, indicating the encoding format is not supported.
"""
1 change: 1 addition & 0 deletions ddtrace/internal/writer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
from .writer import TraceWriter # noqa:F401
from .writer import _human_size # noqa:F401
from .writer_client import WriterClientBase # noqa:F401
from .writer import NativeWriter # noqa:I001,F401
Loading