require 'net/http' require 'json' require 'socket' require 'date' class SdkExceptionHelper 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 end