Class: Datadog::Profiling::HttpTransport

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/profiling/http_transport.rb,
ext/datadog_profiling_native_extension/http_transport.c

Overview

Used to report profiling data to Datadog. Methods prefixed with native are implemented in ‘http_transport.c`

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(agent_settings:, site:, api_key:, upload_timeout_seconds:) ⇒ HttpTransport

Returns a new instance of HttpTransport.

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/datadog/profiling/http_transport.rb', line 13

def initialize(agent_settings:, site:, api_key:, upload_timeout_seconds:)
  @upload_timeout_milliseconds = (upload_timeout_seconds * 1_000).to_i

  @exporter_configuration =
    if agentless?(site, api_key)
      [:agentless, site, api_key].freeze
    else
      [:agent, agent_settings.url].freeze
    end

  status, result = self.class._native_validate_exporter(exporter_configuration)

  raise(ArgumentError, "Failed to initialize transport: #{result}") if status == :error
end

Instance Attribute Details

#exporter_configurationObject (readonly)

Returns the value of attribute exporter_configuration.



11
12
13
# File 'lib/datadog/profiling/http_transport.rb', line 11

def exporter_configuration
  @exporter_configuration
end

Class Method Details

._native_do_exportObject



29
30
31
32
33
34
35
36
37
38
# File 'ext/datadog_profiling_native_extension/http_transport.c', line 29

static VALUE _native_do_export(
  VALUE self,
  VALUE exporter_configuration,
  VALUE upload_timeout_milliseconds,
  VALUE flush,
  VALUE start_timespec_seconds,
  VALUE start_timespec_nanoseconds,
  VALUE finish_timespec_seconds,
  VALUE finish_timespec_nanoseconds
);

._native_validate_exporterObject



26
# File 'ext/datadog_profiling_native_extension/http_transport.c', line 26

static VALUE _native_validate_exporter(VALUE self, VALUE exporter_configuration);

Instance Method Details

#export(flush) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/datadog/profiling/http_transport.rb', line 28

def export(flush)
  status, result = self.class._native_do_export(
    exporter_configuration,
    @upload_timeout_milliseconds,
    flush,
    # TODO: This is going to be removed once we move to libdatadog 17
    flush.start.tv_sec,
    flush.start.tv_nsec,
    flush.finish.tv_sec,
    flush.finish.tv_nsec,
  )

  if status == :ok
    if (200..299).cover?(result)
      Datadog.logger.debug("Successfully reported profiling data")
      true
    else
      Datadog.logger.error(
        "Failed to report profiling data (#{config_without_api_key}): " \
        "server returned unexpected HTTP #{result} status code"
      )
      Datadog::Core::Telemetry::Logger.error(
        "Failed to report profiling data: unexpected HTTP #{result} status code"
      )
      false
    end
  else
    Datadog.logger.error("Failed to report profiling data (#{config_without_api_key}): #{result}")
    Datadog::Core::Telemetry::Logger.error("Failed to report profiling data")
    false
  end
end