-
Notifications
You must be signed in to change notification settings - Fork 15
Add APM tracing support #294
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
Merged
Merged
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
5b68c4d
wip: tracing
astuyve c532836
feat: tracing WIP
astuyve 8b54c2b
feat: rename mini agent to trace agent
astuyve c58c786
feat: fmt
astuyve 7a98a1f
feat: Fix formatting after rename
astuyve a44be55
fix: remove extra tokio task
astuyve 442039d
feat: allow tracing
astuyve 8a02ce8
feat: working v5 traces
astuyve d029b50
feat: Update to use my branch of libdatadog so we have v5 support
astuyve 3f99b22
Merge branch 'main' into aj/add-trace-agent
astuyve e95c8eb
feat: Update w/ libdatadog to pass trace encoding version
astuyve dcb19eb
feat: update w/ merged libdatadog changes
astuyve d53eb85
feat: Refactor trace agent, reduce code duplication, enum for trace v…
astuyve 7171b61
feat: Unify config, remove trace config. Tests pass
astuyve ed76cf3
feat: fmt
astuyve e435e89
feat: fmt
astuyve 2ce64fd
clippy fixes
astuyve c06c5a2
parse time
astuyve aeb64cb
feat: clippy again
astuyve e90cc9f
feat: revert dockerfile
astuyve 63cfecc
feat: no-default-features
astuyve 165c798
feat: Remove utils, take only what we need
astuyve d49402a
feat: fmt moves the import
astuyve 86836e0
feat: replace info with debug. Replace log with tracing lib
astuyve bf040c3
feat: more debug
astuyve 83da528
feat: Remove call to trace utils
astuyve File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| // Copyright 2023-Present Datadog, Inc. https://www.datadoghq.com/ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| pub mod stats_flusher; | ||
| pub mod stats_processor; | ||
| pub mod trace_agent; | ||
| pub mod trace_flusher; | ||
| pub mod trace_processor; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| // Copyright 2023-Present Datadog, Inc. https://www.datadoghq.com/ | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| use async_trait::async_trait; | ||
| use std::str::FromStr; | ||
| use std::sync::Arc; | ||
| use tokio::sync::{mpsc::Receiver, Mutex}; | ||
| use tracing::{debug, error}; | ||
|
|
||
| use crate::config; | ||
| use datadog_trace_protobuf::pb; | ||
| use datadog_trace_utils::config_utils::trace_stats_url; | ||
| use datadog_trace_utils::stats_utils; | ||
| use ddcommon::Endpoint; | ||
|
|
||
| #[async_trait] | ||
| pub trait StatsFlusher { | ||
| /// Starts a stats flusher that listens for stats payloads sent to the tokio mpsc Receiver, | ||
| /// implementing flushing logic that calls flush_stats. | ||
| async fn start_stats_flusher(&self, mut rx: Receiver<pb::ClientStatsPayload>); | ||
| /// Flushes stats to the Datadog trace stats intake. | ||
| async fn flush_stats(&self, traces: Vec<pb::ClientStatsPayload>); | ||
|
|
||
| async fn manual_flush(&self); | ||
| } | ||
|
|
||
| #[allow(clippy::module_name_repetitions)] | ||
| #[derive(Clone)] | ||
| pub struct ServerlessStatsFlusher { | ||
| pub buffer: Arc<Mutex<Vec<pb::ClientStatsPayload>>>, | ||
| pub config: Arc<config::Config>, | ||
| } | ||
|
|
||
| #[async_trait] | ||
| impl StatsFlusher for ServerlessStatsFlusher { | ||
| async fn start_stats_flusher(&self, mut rx: Receiver<pb::ClientStatsPayload>) { | ||
| let buffer_producer = self.buffer.clone(); | ||
|
|
||
| tokio::spawn(async move { | ||
| while let Some(stats_payload) = rx.recv().await { | ||
| let mut buffer = buffer_producer.lock().await; | ||
| buffer.push(stats_payload); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| async fn manual_flush(&self) { | ||
| let mut buffer = self.buffer.lock().await; | ||
| if !buffer.is_empty() { | ||
| self.flush_stats(buffer.to_vec()).await; | ||
| buffer.clear(); | ||
| } | ||
| } | ||
| async fn flush_stats(&self, stats: Vec<pb::ClientStatsPayload>) { | ||
| if stats.is_empty() { | ||
| return; | ||
| } | ||
| debug!("Flushing {} stats", stats.len()); | ||
|
|
||
| let stats_payload = stats_utils::construct_stats_payload(stats); | ||
|
|
||
| debug!("Stats payload to be sent: {stats_payload:?}"); | ||
|
|
||
| let serialized_stats_payload = match stats_utils::serialize_stats_payload(stats_payload) { | ||
| Ok(res) => res, | ||
| Err(err) => { | ||
| error!("Failed to serialize stats payload, dropping stats: {err}"); | ||
| return; | ||
| } | ||
| }; | ||
|
|
||
| let stats_url = trace_stats_url(&self.config.site); | ||
|
|
||
| let endpoint = Endpoint { | ||
| url: hyper::Uri::from_str(&stats_url).expect("can't make URI from stats url, exiting"), | ||
| api_key: Some(self.config.api_key.clone().into()), | ||
| }; | ||
|
|
||
| match stats_utils::send_stats_payload( | ||
| serialized_stats_payload, | ||
| &endpoint, | ||
| &self.config.api_key, | ||
| ) | ||
| .await | ||
| { | ||
| Ok(()) => debug!("Successfully flushed stats"), | ||
| Err(e) => { | ||
| error!("Error sending stats: {e:?}"); | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was gonna say should we remove this? Then I remembered that we are currently targeting Node + Python
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah need all these