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`

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)


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/datadog/profiling/http_transport.rb', line 8

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

  validate_agent_settings(agent_settings)

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

  status, result = validate_exporter(@exporter_configuration)

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

Class Method Details

._native_do_exportObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'ext/datadog_profiling_native_extension/http_transport.c', line 36

static VALUE _native_do_export(
  VALUE self,
  VALUE exporter_configuration,
  VALUE upload_timeout_milliseconds,
  VALUE start_timespec_seconds,
  VALUE start_timespec_nanoseconds,
  VALUE finish_timespec_seconds,
  VALUE finish_timespec_nanoseconds,
  VALUE pprof_file_name,
  VALUE pprof_data,
  VALUE code_provenance_file_name,
  VALUE code_provenance_data,
  VALUE tags_as_array,
  VALUE internal_metadata_json,
  VALUE info_json
);

._native_validate_exporterObject



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

static VALUE _native_validate_exporter(VALUE self, VALUE exporter_configuration);

.log_failure_to_process_tag(failure_details) ⇒ Object

Used to log soft failures in ‘ddog_Vec_tag_push` (e.g. we still report the profile in these cases) Called from native code



69
70
71
# File 'lib/datadog/profiling/http_transport.rb', line 69

def self.log_failure_to_process_tag(failure_details)
  Datadog.logger.warn("Failed to add tag to profiling request: #{failure_details}")
end

Instance Method Details

#export(flush) ⇒ Object



25
26
27
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
60
61
62
63
64
65
# File 'lib/datadog/profiling/http_transport.rb', line 25

def export(flush)
  status, result = do_export(
    exporter_configuration: @exporter_configuration,
    upload_timeout_milliseconds: @upload_timeout_milliseconds,

    # why "timespec"?
    # libdatadog represents time using POSIX's struct timespec, see
    # https://www.gnu.org/software/libc/manual/html_node/Time-Types.html
    # aka it represents the seconds part separate from the nanoseconds part
    start_timespec_seconds: flush.start.tv_sec,
    start_timespec_nanoseconds: flush.start.tv_nsec,
    finish_timespec_seconds: flush.finish.tv_sec,
    finish_timespec_nanoseconds: flush.finish.tv_nsec,

    pprof_file_name: flush.pprof_file_name,
    pprof_data: flush.pprof_data,
    code_provenance_file_name: flush.code_provenance_file_name,
    code_provenance_data: flush.code_provenance_data,

    tags_as_array: flush.tags_as_array,
    internal_metadata_json: flush.,

    info_json: flush.info_json
  )

  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"
      )
      false
    end
  else
    Datadog.logger.error("Failed to report profiling data (#{config_without_api_key}): #{result}")
    false
  end
end