Tracing works from Swagger but not when called from website - c#

I'm adding tracing to my .NET Core Web API projects.
When I call into my endpoints using Swagger, I see the traces in Zipkin that go across multiple services because of the OpenTelemetry.Instrumentation.Http package that I installed.
So far so good.
The problem comes when I try to hit those same exact endpoints from my actual web application. No traces are captured. Best guess is that something needs to be added to the website as well.
Optimally, what I would like to do is...
start a new span (System.Diagnostics.Activity) if one doesn't come across the wire. That way regardless of what calls me, I can still capture a trace through my various systems.
Anyone have an idea on how to do that?

Related

Using a Web Api 2 project to authenticate/authorize a separate client project's users

I'm having trouble getting the authentication portion working, particularly the external authentication. I'm using a client project to call my API, which then handles all the OAuth processing.
My issue is that once you authenticate through Facebook, it wants to redirect to my API url, and that redirect url has the access_code needed for authorization of subsequent API calls from the client. Is there a best practice for dealing with this situation? For instance, should I parse the access_code out of the url and somehow send it back to the client project?
Searching for how to handle this yields me vague results. Most everything I come across leads back to one of two links:
This is helpful understanding the high level concept
This implies that you should just dig around in the SPA template and figure it out on your own
neither of which really help me out much in a "how-to" sense.
The client project I'm ultimately working with is a Xamarin project, so I'm looking for C# or Xamarin library code how-tos in particular. If anyone can help, I'd appreciate it.

Examples showing conversion of a WCF REST service to ASP.NET OWIN?

I've got a stand alone WCF service providing REST services. As time goes on, I'm feeling like MS is going to reduce support for WCF and REST services, and I've already had to code in a bunch of hacks to get somethings working like CORS. Additionally, implementing https is another hack since it requires using OS functionality. (i.e. you have to install the certificate using an external application, which doesnt' make the service very self contained)
In anycase, I'm considering either a move to ASP.NET REST API and OWIN, or Java/Spring. I wanted to first see what it would take to move to ASP.NET REST, since I figured that should take the smallest amount of work, but I haven't found any good examples.
There's a pretty straightforward example on the asp.net site.
http://www.asp.net/web-api/overview/hosting-aspnet-web-api/use-owin-to-self-host-web-api
setup a self-contained project i.e console app or windows service
initialise and setup you routes
create your Controller / API stubs
deploy
Regarding SSL, whether it's IIS or Apache you will have to configure it on the web server regardless.

SaaS development using .Net

I do not know how to explain this in technical terms. So let me begin with an example:
Story
I have an online e-commerce site www.ABCStore.com . I built this using MVC 4 (Razor) in Dot Net.
My friend has a travel agency for which his online site is www.DEFAgency.com . He got it built in Java.
Both our websites were up and running. One fine day I got a call from a company FicticiousServiceProvider and they asked me if I would be interested in getting customer feedback as a functionality on my website without having to write any code myself. What they offered was, I would have to include just a single line of code in the footer of my Masterpage(or layout page) and then the customers who log on to the site would see a small icon on the pages and would be able to provide their feedback.
The feedback will not be available directly to me. The FicticiousServiceProvider guys will analyze the data and provide them to me on a regular basis or on a need basis.
There were other services too which they offered.
I was really happy to have a functionality like that, specially without having to write any code. I tried it and it worked fine in my .Net website. My friend(with a java website) also added a single line to his code and it worked for him too.
My questions here are:
What is this process called ?
If I were FicticiousServiceProvider, how would I have developed this using .Net ? I mean, how to develop a functionality so that a consumer can consume the service using a single line provided by the service provider. Data transfer from my site in the form of feedback to the FicticiousServiceProvider is also happening, without me being able to see anything.
How was it possible for FicticiousServiceProvider to provide the functionality to a .Net app and a java app without any change in the line provided by them?
I have given the description from a consumers perspective. Please suggest from a developer's perspective. Many Thanks.
These things, like Google Analytics tracking code, are usually some kind of javascript injecton. It will use javascript to 'inject' a bit of code that sends a request to their servers (what their server side is coded in is irrelevant really). They then handle the request that includes the information they've gathered in javascript on the client side and store it, then use server side software to analyse that data to give out reports, etc..
So to try and answer your question separately.
I'd call the process javascript injection.
You would have to find the best way to send a request to your servers and handle that request. Could be done with ASP.Net MVC quite easily but any server side technology/code that can handle requests and send data to a store.
They use javascript which is separate to any server side code and works across browsers on the client side.

New Relic ASP.NET Web API

I am trying to use New Relic's .NET Agent in my Web API but all requests are being shown as System.Web.Http.WebHost.HttpControllerHandler, which is exactly what the docs known issues section says
MVC 4 (Note: New Relic provides limited support for the ASP .NET Web API for MVC4. All Web API transactions will appear as
HttpControllerHandler, not as the name of the web API controller.)
I am looking for any workaround that results in a more human readable dashboard, Is there any configuration in my app or IIS that I could change to have a more meaningful metric in my dashboard? Or is there a way of implementing the API calls in order to change this behavior?
NewRelic has released an update to the .NET Agent which should solve your problem.
See: https://newrelic.com/docs/releases/dotnet. "Improved WebAPI support. You should now see Web Transactions grouped by [controller].[action] rather than all WebAPI transactions reporting as System.Web.Http.WebHost.HttpControllerHandler."
you may get some better results by setting transaction names via the API. But, until New Relic improves overall support for ASP.NET Web API, there isn't a way to arbitrarily stuff things into web transactions.
https://newrelic.com/docs/dotnet/the-net-agent-api
SetTransactionName()
Also, if you specify certain methods to trace, when things are slow and a transaction trace gets generated, you'll see these custom method tracers appear in the trace details tree view.
https://newrelic.com/docs/dotnet/CustomInstrumentation
This is quite an old post but I spent quite a bit of time looking into a similar issue and in my case these delays were only appearing during POST where http message had request content.
In the long run, this was due to network performance problems (mobile clients) and the POST was trying to read the body of the message which is taking a long time to transmit. The take away being that these delays while showing in the controller handler were actually just waiting for the request body to be transmitted.

Silverlight WebApp Calling Webservice in the same solution

I have a website solution that is composed of a Silverlight Project and an ASP Site that contains an asmx Webservice.
The Silverlight project calls various methods in the Webservice, and this works fine on my home PC.
When I publish the site (using 123-Reg if that makes a difference), it appears that the Silverlight app is no longer able to call the webservice. I have tried debugging the app by pointing my local version of the site to my published webservice and I get a "policy" issue.
I know that 123 Reg have .Net 3.5 running on their servers, so I would assume that the site should "just work" when I publish it. Am I making a hugely stupid assumption there? Is there anything that I can do to change the "policies" within my app? Or is there another way around what I am trying to do? I need to keep the webservice, as I want for it to be used from other places, and don't really want to duplicate code and create the same methods within the Silverlight project.
Thanks
Soundlike you are hitting a crossdomain issue, though you shouldn't really.
I would stick a clientaccesspolicy.xml in the root of you web server.
There are loads of questions on SO if you need examples or MSDN

Categories