datadog 2.11.0 → 2.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,79 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'error'
4
- require_relative '../core/transport/http/adapters/net'
5
-
6
- module Datadog
7
- module DI
8
- # Transport for sending probe statuses and snapshots to local agent.
9
- #
10
- # Handles encoding of the payloads into multipart posts if necessary,
11
- # body formatting/encoding, setting correct headers, etc.
12
- #
13
- # The transport does not handle batching of statuses or snapshots -
14
- # the batching should be implemented upstream of this class.
15
- #
16
- # Timeout settings are forwarded from agent settings to the Net adapter.
17
- #
18
- # The send_* methods raise Error::AgentCommunicationError on errors
19
- # (network errors and HTTP protocol errors). It is the responsibility
20
- # of upstream code to rescue these exceptions appropriately to prevent them
21
- # from being propagated to the application.
22
- #
23
- # @api private
24
- class Transport
25
- DIAGNOSTICS_PATH = '/debugger/v1/diagnostics'
26
- INPUT_PATH = '/debugger/v1/input'
27
-
28
- def initialize(agent_settings)
29
- # Note that this uses host, port, timeout and TLS flag from
30
- # agent settings.
31
- @client = Core::Transport::HTTP::Adapters::Net.new(agent_settings)
32
- end
33
-
34
- def send_diagnostics(payload)
35
- event_payload = Core::Vendor::Multipart::Post::UploadIO.new(
36
- StringIO.new(JSON.dump(payload)), 'application/json', 'event.json'
37
- )
38
- payload = {'event' => event_payload}
39
- # Core transport unconditionally specifies headers to underlying
40
- # Net::HTTP client, ends up passing 'nil' as headers if none are
41
- # specified by us, which then causes Net::HTTP to die with an exception.
42
- send_request('Probe status submission',
43
- path: DIAGNOSTICS_PATH, form: payload, headers: {})
44
- end
45
-
46
- def send_input(payload)
47
- send_request('Probe snapshot submission',
48
- path: INPUT_PATH, body: payload.to_json,
49
- headers: {'content-type' => 'application/json'},)
50
- end
51
-
52
- # TODO status should use either input or diagnostics endpoints
53
- # depending on agent version.
54
- alias_method :send_status, :send_diagnostics
55
-
56
- alias_method :send_snapshot, :send_input
57
-
58
- private
59
-
60
- attr_reader :client
61
-
62
- def send_request(desc, **options)
63
- env = Core::Transport::HTTP::Env.new(nil, options)
64
- response = client.post(env)
65
- unless response.ok?
66
- raise Error::AgentCommunicationError, "#{desc} failed: #{response.code}: #{response.payload}"
67
- end
68
- # Datadog::Core::Transport does not perform any exception mapping,
69
- # therefore we could have any exception here from failure to parse
70
- # agent URI for example.
71
- # If we ever implement retries for network errors, we should distinguish
72
- # actual network errors from non-network errors that are raised by
73
- # transport code.
74
- rescue => exc
75
- raise Error::AgentCommunicationError, "#{desc} failed: #{exc.class}: #{exc}"
76
- end
77
- end
78
- end
79
- end