|
13 | 13 | using OpenTelemetry.Metrics; |
14 | 14 | using OpenTelemetry.Trace; |
15 | 15 |
|
16 | | -var builder = WebApplication.CreateSlimBuilder(args); |
| 16 | +try |
| 17 | +{ |
| 18 | + var process = System.Diagnostics.Process.GetCurrentProcess(); |
| 19 | + Console.WriteLine($"Starting Lambda application... Memory: {process.WorkingSet64 / 1024 / 1024} MB"); |
| 20 | + |
| 21 | + var builder = WebApplication.CreateSlimBuilder(args); |
| 22 | + process.Refresh(); |
| 23 | + Console.WriteLine($"WebApplication builder created. Memory: {process.WorkingSet64 / 1024 / 1024} MB"); |
| 24 | + |
| 25 | + _ = builder.AddDocumentationServiceDefaults(ref args); |
| 26 | + process.Refresh(); |
| 27 | + Console.WriteLine($"Documentation service defaults added. Memory: {process.WorkingSet64 / 1024 / 1024} MB"); |
| 28 | + |
| 29 | + _ = builder.AddElasticOpenTelemetry(edotBuilder => |
| 30 | + { |
| 31 | + _ = edotBuilder |
| 32 | + .WithElasticTracing(tracing => |
| 33 | + { |
| 34 | + _ = tracing |
| 35 | + .AddAspNetCoreInstrumentation() |
| 36 | + .AddHttpClientInstrumentation(); |
| 37 | + }) |
| 38 | + .WithElasticLogging() |
| 39 | + .WithElasticMetrics(metrics => |
| 40 | + { |
| 41 | + _ = metrics |
| 42 | + .AddAspNetCoreInstrumentation() |
| 43 | + .AddHttpClientInstrumentation() |
| 44 | + .AddProcessInstrumentation() |
| 45 | + .AddRuntimeInstrumentation(); |
| 46 | + }); |
| 47 | + }); |
| 48 | + |
| 49 | + process.Refresh(); |
| 50 | + Console.WriteLine($"Elastic OTel configured. Memory: {process.WorkingSet64 / 1024 / 1024} MB"); |
| 51 | + |
| 52 | + _ = builder.Services.AddAWSLambdaHosting(LambdaEventSource.RestApi, new SourceGeneratorLambdaJsonSerializer<LambdaJsonSerializerContext>()); |
| 53 | + process.Refresh(); |
| 54 | + Console.WriteLine($"AWS Lambda hosting configured. Memory: {process.WorkingSet64 / 1024 / 1024} MB"); |
| 55 | + |
| 56 | + var environment = Environment.GetEnvironmentVariable("ENVIRONMENT"); |
| 57 | + Console.WriteLine($"Environment: {environment}"); |
| 58 | + |
| 59 | + builder.Services.AddElasticDocsApiUsecases(environment); |
| 60 | + process.Refresh(); |
| 61 | + Console.WriteLine($"Elastic docs API use cases added. Memory: {process.WorkingSet64 / 1024 / 1024} MB"); |
| 62 | + |
| 63 | + _ = builder.WebHost.UseKestrelHttpsConfiguration(); |
| 64 | + process.Refresh(); |
| 65 | + Console.WriteLine($"Kestrel HTTPS configuration applied. Memory: {process.WorkingSet64 / 1024 / 1024} MB"); |
| 66 | + |
| 67 | + var app = builder.Build(); |
| 68 | + process.Refresh(); |
| 69 | + Console.WriteLine($"Application built successfully. Memory: {process.WorkingSet64 / 1024 / 1024} MB"); |
17 | 70 |
|
18 | | -builder.AddDocumentationServiceDefaults(ref args); |
| 71 | + var v1 = app.MapGroup("/docs/_api/v1"); |
| 72 | + v1.MapElasticDocsApiEndpoints(); |
| 73 | + Console.WriteLine("API endpoints mapped"); |
19 | 74 |
|
20 | | -builder.Services.AddAWSLambdaHosting(LambdaEventSource.RestApi, new SourceGeneratorLambdaJsonSerializer<LambdaJsonSerializerContext>()); |
21 | | -builder.AddElasticOpenTelemetry(edotBuilder => |
| 75 | + Console.WriteLine("Application startup completed successfully"); |
| 76 | + app.Run(); |
| 77 | +} |
| 78 | +catch (Exception ex) |
22 | 79 | { |
23 | | - _ = edotBuilder |
24 | | - .WithElasticTracing(tracing => |
25 | | - { |
26 | | - _ = tracing |
27 | | - .AddAspNetCoreInstrumentation() |
28 | | - .AddHttpClientInstrumentation(); |
29 | | - }) |
30 | | - .WithElasticLogging() |
31 | | - .WithElasticMetrics(metrics => |
32 | | - { |
33 | | - _ = metrics |
34 | | - .AddAspNetCoreInstrumentation() |
35 | | - .AddHttpClientInstrumentation() |
36 | | - .AddProcessInstrumentation() |
37 | | - .AddRuntimeInstrumentation(); |
38 | | - }); |
39 | | -}); |
40 | | - |
41 | | -builder.Services.AddElasticDocsApiUsecases(Environment.GetEnvironmentVariable("ENVIRONMENT")); |
42 | | -builder.WebHost.UseKestrelHttpsConfiguration(); |
43 | | - |
44 | | -var app = builder.Build(); |
45 | | -var v1 = app.MapGroup("/docs/_api/v1"); |
46 | | -v1.MapElasticDocsApiEndpoints(); |
47 | | - |
48 | | -app.Run(); |
| 80 | + Console.WriteLine($"FATAL ERROR during startup: {ex}"); |
| 81 | + Console.WriteLine($"Exception type: {ex.GetType().Name}"); |
| 82 | + Console.WriteLine($"Stack trace: {ex.StackTrace}"); |
| 83 | + throw; |
| 84 | +} |
49 | 85 |
|
50 | 86 | [JsonSerializable(typeof(APIGatewayProxyRequest))] |
51 | 87 | [JsonSerializable(typeof(APIGatewayProxyResponse))] |
|
0 commit comments