Core/Exception/SdkExceptionHelper.pm untested

filter: Statementstmt 0.0% 0 / 50 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 67 CC 2 SCAR 10.6
CC
2
Cov
0%
send_exception_to_app_insights
6.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.9
1 use strict;
2 use warnings;
3 use LWP::UserAgent;
4 use DateTime;
5 use Sys::Hostname;
6 use threads;
7 use Nice::Try;
8
9 my $address = "https://dc.services.visualstudio.com/v2/track";
10 my $instrumentationKey = "2c751560-90c8-40e9-b5dd-534566514723";
11
12 package Javonet::Core::Exception::SdkExceptionHelper;
13
14 sub send_exception_to_app_insights {
15 my ($class, $event, $license_key) = @_;
16 try {
17 my $ua = LWP::UserAgent->new;
18 $ua->default_header('Accept' => 'application/json');
19
20 # Path to the VERSION file
21 my $version_file_path = 'VERSION';
22
23 # Variable to hold the javonet version
24 my $javonet_version;
25
26 try {
27 # Open the VERSION file for reading
28 open(my $fh, '<', $version_file_path) or die "Could not open file '$version_file_path' $!";
29
30 # Read the first line of the file
31 my $first_line = <$fh>;
32
33 # Use a regular expression to extract the version number
34 if ($first_line =~ /^\$VERSION=(.+)$/) {
35 $javonet_version = $1;
36 }
37
38 # Close the file handle
39 close($fh);
40 }
41 catch ( $e ) {
42 $javonet_version = "2.0.0";
43 };
44
45 my $node_name = eval {hostname()} || "Unknown Host";
46
47 my $operation_name = "JavonetSdkException";
48 my $os_name = $^O; # Replace with your desired OS name
49 my $calling_runtime_name = "Perl"; # Replace with your desired runtime name
50 my $event_message = $event;
51
52 my $dt = DateTime->now(time_zone => 'GMT');
53
54 # Format the DateTime object to a string
55 my $formatted_datetime = $dt->strftime("%Y-%m-%dT%H:%M:%S");
56
57 my $payload = "{"
58 . "\"name\": \"AppEvents\","
59 . "\"time\": \"$formatted_datetime\","
60 . "\"iKey\": \"$instrumentationKey\","
61 . "\"tags\": {"
62 . "\"ai.application.ver\": \"$javonet_version\","
63 . "\"ai.cloud.roleInstance\": \"$node_name\","
64 . "\"ai.operation.id\": \"0\","
65 . "\"ai.operation.parentId\": \"0\","
66 . "\"ai.operation.name\": \"$operation_name\","
67 . "\"ai.internal.sdkVersion\": \"$javonet_version\","
68 . "\"ai.internal.nodeName\": \"$node_name\""
69 . "},"
70 . "\"data\": {"
71 . "\"baseType\": \"EventData\","
72 . "\"baseData\": {"
73 . "\"ver\": 2,"
74 . "\"name\": \"$event_message\","
75 . "\"properties\": {"
76 . "\"OperatingSystem\": \"$os_name\","
77 . "\"LicenseKey\": \"$license_key\","
78 . "\"CallingTechnology\": \"$calling_runtime_name\""
79 . "}"
80 . "}"
81 . "}"
82 . "}";
83
84 my $response = $ua->post($address, Content => $payload);
85 my $response_code = $response->code;
86 return $response_code;
87 }
88 catch ( $e ) {
89 return 500;
90 }
91 }
92
93 1;