Class: SdkExceptionHelper

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

Class Method Summary collapse

Class Method Details

.send_exception_to_app_insights(e, license_key) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/javonet-ruby-sdk/sdk/tools/sdk_exception_helper.rb', line 10

def self.send_exception_to_app_insights(e, license_key)
  Thread.new do
    begin
      instrumentation_key = "2c751560-90c8-40e9-b5dd-534566514723"
      client = Net::HTTP.new('dc.services.visualstudio.com', 443)
      client.use_ssl = true

      javonet_version = "2.0.0" # Replace with your desired version
      node_name = Socket.gethostname rescue "Unknown Host"
      operation_name = "JavonetSdkException"
      os_name =
      if RUBY_PLATFORM =~ /darwin/
        "MacOS"
      elsif RUBY_PLATFORM =~ /linux/
        "Linux"
      elsif RUBY_PLATFORM =~ /freebsd/
        "FreeBSD"
      elsif RUBY_PLATFORM =~ /mswin|msys|mingw|cygwin|bccwin|wince|emc/
        "Windows"
      else
        "Unknown"
      end
      calling_runtime_name = "Ruby"
      event_message = e.to_s

      formatted_datetime = Time.now.gmtime.strftime("%Y-%m-%dT%H:%M:%S")

      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": event_message,
            "properties": {
              "OperatingSystem": os_name,
              "LicenseKey": license_key,
              "CallingTechnology": calling_runtime_name
            }
          }
        }
      }

      request = Net::HTTP::Post.new('/v2/track')
      request['Content-Type'] = 'application/json'
      request.body = payload.to_json

      response = client.request(request)
      response_code = response.code.to_i
      response_code
    rescue Exception => ex
      puts ex
      500
    end
  end
end