'ActivitySource.StartActivity returns null as if there is no listeners even though console listener is defined
The code uses Console Trace Provider. However, In the function static void MakeActivity(string name), The line ActivitySource.startActivity returns a null. How can i fix it?
The examples on google have the "using" keyword which i cannot apply with .net 4.7 with which my project id bound against.
/// <summary>
/// Starts up the OpenTelemetry and JeagerTracing connection
/// </summary>
using OpenTelemetry;
using OpenTelemetry.Resources;
using OpenTelemetry.Trace;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UnitTestProject1
{
class Program
{
private static ResourceBuilder BackendServiceResource { get; set; }
private static readonly ActivitySource ActivitySource = new ActivitySource("Sample.DistributedTracing");
private static readonly string serveradress = "127.0.0.1";
private static readonly int serverPort = 6831;
public static TracerProvider Provider { get; set; }
public static Tracer OpenTelemetryTracer { get; set; }
static void Main(string[] args)
{
var serviceName = "MyCompany.MyProduct.MyService";
var serviceVersion = "1.0.0";
Provider = GetConsoleTraceProvider(serviceName, serviceVersion);
OpenTelemetryTracer = Provider.GetTracer(ActivitySource.Name);
MakeActivity("Test 1");
MakeActivity("Test 2");
MakeActivity("Test 3");
MakeActivity("Test 4");
MakeActivity("Test 5");
}
static void MakeActivity(string name)
{
Activity activity = ActivitySource.StartActivity(name); // this returns null even though i have a trace provider setup using GetConsoleTraceProvider
activity.AddTag("machine.name", Environment.MachineName);
activity.AddTag("user.name", Environment.UserName);
Task.Delay(5000);
activity.Stop();
}
public static TracerProvider GetConsoleTraceProvider(string serviceName,string serviceVersion)
{
// Configure important OpenTelemetry settings and the console exporter
var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddSource(serviceName)
.SetResourceBuilder(
ResourceBuilder.CreateDefault()
.AddService(serviceName: serviceName, serviceVersion: serviceVersion))
.AddConsoleExporter()
.Build();
return tracerProvider;
}
}
}
vs this code sample works as i am using a c# 10 feature.
using System.Diagnostics;
using OpenTelemetry;
using OpenTelemetry.Trace;
using OpenTelemetry.Resources;
using OpenTelemetry.Exporter;
// Define some important constants and the activity source
var serviceName = "MyCompany.MyProduct.MyService";
var serviceVersion = "1.0.0";
// Configure important OpenTelemetry settings and the console exporter
using var tracerProvider = Sdk.CreateTracerProviderBuilder()
.AddSource(serviceName)
.SetResourceBuilder(
ResourceBuilder.CreateDefault()
.AddService(serviceName: serviceName, serviceVersion: serviceVersion))
.AddConsoleExporter()
.Build();
var MyActivitySource = new ActivitySource(serviceName);
using var activity = MyActivitySource.StartActivity("SayHello");
activity?.SetTag("foo", 1);
activity?.SetTag("bar", "Hello, World!");
activity?.SetTag("baz", new int[] { 1, 2, 3 });
Solution 1:[1]
"SAS7BDAT is a closed file format, and not intended to be read/written to by other languages; some have reverse engineered enough of it to read at least, but from what I've seen no good SAS7BDAT writer exists."
Although the SAS7BDAT is a proprietary format, it is not closed. It can be read and written by third-party products using SAS' own ODBC drivers. https://support.sas.com/en/software/sas-odbc-drivers.html. Since Python can use ODBC (pyodbc), just use the SAS ODBC Driver to write the SAS7BDAT file format.
IBM SPSS Statistics and IBM SPSS Modeler can also read and write the SAS7BDAT format as well as the earlier pre-version 7 formats and the SAS Transport File format (the .xpt) files noted above. These products do not require ODBC to do this and this capability is included in SPSS Statistics Base via the SAVE Translate command. It is included in SPSS Modeler Professional via the SAS Source node for reading and the SAS Export node for writing.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | David A. West |
