Class: Hypertube::Sdk::Tools::SdkMessageHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/hypertube-ruby-sdk/sdk/tools/sdk_message_helper.rb

Constant Summary collapse

ADDRESS =
"https://dc.services.visualstudio.com/v2/track"
INSTRUMENTATION_KEY =
"2c751560-90c8-40e9-b5dd-534566514723"
CALLING_RUNTIME_NAME =
"Ruby"
VERSION =
Gem.loaded_specs["hypertube-ruby-sdk"]&.version.to_s || "Unknown"
NODE_NAME =
Socket.gethostname rescue "Unknown Host"
OS_NAME =
case RUBY_PLATFORM
when /darwin/ then "MacOS"
when /linux/ then "Linux"
when /freebsd/ then "FreeBSD"
when /mswin|msys|mingw|cygwin|bccwin|wince|emc/ then "Windows"
else "Unknown"
end

Class Method Summary collapse

Class Method Details

.send_message_to_app_insights(operation_name, message) ⇒ Object



24
25
26
27
28
# File 'lib/hypertube-ruby-sdk/sdk/tools/sdk_message_helper.rb', line 24

def self.send_message_to_app_insights(operation_name, message)
  Thread.new do
    send_message_to_app_insights_func(operation_name, message)
  end
end

.send_message_to_app_insights_func(operation_name, message) ⇒ Object



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
66
67
68
69
70
71
72
73
# File 'lib/hypertube-ruby-sdk/sdk/tools/sdk_message_helper.rb', line 30

def self.send_message_to_app_insights_func(operation_name, message)
  begin
    formatted_datetime = Time.now.utc.strftime("%Y-%m-%dT%H:%M:%S")
    license_key = Hypertube::Sdk::Tools::ActivationHelper.get_license_key
    payload = {
      "name": "AppEvents",
      "time": formatted_datetime,
      "iKey": INSTRUMENTATION_KEY,
      "tags": {
        "ai.application.ver": VERSION,
        "ai.cloud.roleInstance": NODE_NAME,
        "ai.operation.id": "0",
        "ai.operation.parentId": "0",
        "ai.operation.name": operation_name,
        "ai.internal.sdkVersion": "hypertube",
        "ai.internal.nodeName": NODE_NAME
      },
      "data": {
        "baseType": "EventData",
        "baseData": {
          "ver": 2,
          "name": message,
          "properties": {
            "OperatingSystem": OS_NAME,
            "LicenseKey": license_key,
            "CallingTechnology": CALLING_RUNTIME_NAME
          }
        }
      }
    }

    uri = URI(ADDRESS)
    request = Net::HTTP::Post.new(uri, 'Content-Hypertube::Utils::Type' => 'application/json')
    request.body = payload.to_json

    response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
      http.request(request)
    end

    response.code.to_i
  rescue Exception => e
    500
  end
end