Class: MicrosoftGraphCore::Middleware::TelemetryHandler

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/microsoft_graph_core/middleware/telemetry_handler.rb

Constant Summary collapse

@@default_option =
GraphClientOptions.new

Instance Method Summary collapse

Instance Method Details

#call(request_env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/microsoft_graph_core/middleware/telemetry_handler.rb', line 12

def call(request_env)
				request_option = request_env[:request][:context][@@default_option.get_key] unless request_env[:request].nil? || request_env[:request][:context].nil?
    request_option = @@default_option if request_option.nil?
				header_value = get_header_value(request_option)
    unless header_value.nil? || header_value.empty? || request_env[:request_headers].nil? then
        request_env[:request_headers]["SdkVersion"] = header_value
        request_env[:request_headers]["client-request-id"] = SecureRandom.uuid
    end
    @app.call(request_env) unless app.nil?
end

#get_header_value(options) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/microsoft_graph_core/middleware/telemetry_handler.rb', line 23

def get_header_value(options)
	if options.nil? then
		options = GraphClientOptions.new
	end
	service_version_prefix = ""
	unless options.graph_service_library_version.nil? || options.graph_service_library_version.empty? then
		service_version_prefix = "graph-ruby"
		unless options.graph_service_version.nil? || options.graph_service_version.empty? then
			service_version_prefix += "-" + options.graph_service_version
		end
		service_version_prefix += "/" + options.graph_service_library_version + ","
	end
	feature_suffix = ""
	unless RbConfig::CONFIG["host_os"].nil? || RbConfig::CONFIG["host_os"].empty? then
		feature_suffix = " hostOS=" + RbConfig::CONFIG["host_os"] + ";"
	end
	unless RbConfig::CONFIG["host_cpu"].nil? || RbConfig::CONFIG["host_cpu"].empty? then
		feature_suffix += " hostArch=" + RbConfig::CONFIG["host_cpu"] + ";"
	end
	unless RbConfig::CONFIG["ruby_version"].nil? || RbConfig::CONFIG["ruby_version"].empty? then
		feature_suffix += " runtimeEnvironment=" + RbConfig::CONFIG["ruby_version"] + ";"
	end
	return service_version_prefix + "graph-ruby-core/" + MicrosoftGraphCore::VersionInformation::VERSION + feature_suffix
end