protected override async Task HandleReport(StacktraceReport report) { foreach (var stackFrame in report.Stack.Where(x => !string.IsNullOrEmpty(x.FileName))) { SourceMap sourceMap = null; var url = stackFrame.FileName; try { var uri = new Uri(url); if (!uri.Scheme.Equals("http", StringComparison.InvariantCultureIgnoreCase) && !uri.Scheme.Equals("https", StringComparison.InvariantCultureIgnoreCase)) { continue; } if (!setings.IsAllowedDomain(uri.Host)) { log.Error($"{url} doesn't contain allowed domain"); continue; } if (!setings.IsAllowedDomainForSourceMap(uri.Host)) { log.Debug($"{url} domain doesn't support sourcemaps"); continue; } if (!cache.Get(url, out sourceMap)) { sourceMap = await GetMapFromUrl(url); cache.Set(url, sourceMap, expirationTimeSpan); } } catch (Exception e) { log.Error($"failed to get sourcemap from url: {url}", e); } var mappingEntry = sourceMap?.GetMappingEntryForGeneratedSourcePosition( new SourcePosition { ZeroBasedLineNumber = stackFrame.LineNumber - 1, ZeroBasedColumnNumber = stackFrame.ColumnNumber - 1 }); if (mappingEntry != null) { stackFrame.LineNumber = mappingEntry.OriginalSourcePosition.ZeroBasedLineNumber + 1; stackFrame.ColumnNumber = mappingEntry.OriginalSourcePosition.ZeroBasedColumnNumber + 1; stackFrame.FileName = mappingEntry.OriginalFileName; stackFrame.FunctionName = mappingEntry.OriginalName; log.Debug("report before patching:\n" + report.ToPrettyJson()); } } }
public Task Invoke(HttpContext context) { var origin = context.Request.Headers["Origin"]; if (!setings.IsAllowedDomain(origin)) { log.ForContext("domain", origin).Info("domain not in whitelist"); } else { context.Response.Headers["Access-Control-Allow-Origin"] = origin; context.Response.Headers["Access-Control-Allow-Methods"] = "GET, POST, OPTIONS"; context.Response.Headers["Access-Control-Allow-Headers"] = "Content-Type"; } return(next(context)); }