Class: SdkMessageHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/javonet-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"
JAVONET_VERSION =
Gem.loaded_specs["javonet-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



21
22
23
24
25
# File 'lib/javonet-ruby-sdk/sdk/tools/sdk_message_helper.rb', line 21

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



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
66
67
68
69
70
# File 'lib/javonet-ruby-sdk/sdk/tools/sdk_message_helper.rb', line 27

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 = ActivationHelper.get_license_key
    payload = {
      "name": "AppEvents",
      "time": formatted_datetime,
      "iKey": INSTRUMENTATION_KEY,
      "tags": {
        "ai.application.ver": JAVONET_VERSION,
        "ai.cloud.roleInstance": NODE_NAME,
        "ai.operation.id": "0",
        "ai.operation.parentId": "0",
        "ai.operation.name": operation_name,
        "ai.internal.sdkVersion": "javonet:2",
        "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-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