question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Refactor track* API

See original GitHub issue

Before we ship stable SDK I would like to refactor track API:

  1. To make track* functions more consistent between themselves.
  2. To allow specifying timestamp
  3. To address some reported bugs such as inability to specify result code for dependencies #286 and not being able to track requests without request object #148
  4. To make names consistent with property names in Portal and Analytics
  5. To make API consistent with .NET API
  6. To reduce the number of positional argument to the ones required, while keeping the others in TrackOptions bag.

This is the proposal:


interface TrackOptions
{
    timestamp?: Date;
    properties?: { [key: string]: string; }
    measurements?:{ [key: string]: number; }
    contextObjects?: {[name: string]: any;}
    tagOverrides?: { [key: string]: string; }
}

void trackDependency(
     dependencyTypeName: string,
     target: string,
     dependencyName: string,
     data: string,
     duration: number,
     resultCode: string
     success: bool
     trackOptions: TrackOptions);

void trackEvent(
     eventName: string,
     trackOptions: TrackOptions);

void trackTrace(
     message: string,
     severityLevel: SeverityLevel
     trackOptions: TrackOptions);

void trackMetric(
     metricName: string,
     metricValue: number
     trackOptions: TrackOptions);

void trackException(
     exception: Error,
     trackOptions: TrackOptions);

void trackRequest(
     name: string,
     duration: number,
     resultCode: string
     success: bool
     trackOptions: TrackOptions);

@OsvaldoRosado @SergeyKanzhelev @KamilSzostak

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:14 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
AlexBulankoucommented, Aug 24, 2017

Discussed with Sergey and decided to do 2 changes:

  1. Rename *TrackOptions-> *Telemetry for consistency with .NET and also not to introduce additional concept:
  • RequestTelemetry
  • DependencyTelemetry
  • MetricTelemetry
  • ExceptionTelemetry
  • EventTelemetry
  • TraceTelemetry
  1. Don’t expose domain specific objects, such as http, https, http.RequestOptions in the Client API. This way API remains clean and can be easier shared with JS later on. Instead create helpers to create RequestTelemetry from req/res and DependencyTelemetry from ClientRequest With this API becomes:
class Util
{
 public createDependencyTelemetryFromClientRequest(clientRequest:http.ClientRequest|https.ClientRequest, requestOptions: http.RequestOptions|https.RequestOptions): DependencyTelemetry;
 public createRequestTelemetryFromHttpRequestAsync(httpRequest: http.Request | https.Request, httpResponse: http.Response | https.Response, onRequestComplete:()=>RequestTelemetry): void;
 public createRequestTelemetryFromHttpRequest(httpRequest: http.Request | https.Request, httpResponse: http.Response | https.Response, duration: number): RequestTelemetry;
}

interface Telemetry
{
    timestamp?: Date;
    properties?: { [key: string]: string; };
    measurements?:{ [key: string]: number; };
    contextObjects?: {[name: string]: any;};
    tagOverrides?: { [key: string]: string; };
}

interface DependencyTelemetry extends Telemetry
{
     dependencyTypeName: string;
     target: string;
     dependencyName: string;
     data: string;
     duration: number;
     resultCode: string;
     success: bool;
}

interface EventTelemetry extends Telemetry
{
     eventName: string
}

interface TraceTelemetry extends Telemetry
{
     message: string;
     severityLevel: SeverityLevel;
}

interface ExceptionTelemetry extends Telemetry
{
     exception: Error;
}

interface MetricTelemetry extends Telemetry
{
     name: string;
     value: number;
     count: number;
     min: number;
     max: number;
     stdDev: number;
}

interface RequestTelemetry extends Telemetry
{
     name: string;
     duration: number;
     resultCode: string;
     success: bool;
}

public class Client
{
  public void trackDependency(telemetry: DependencyTelemetry);
  public void trackTrace(telemetry: TraceTelemetry); 
  public void trackMetric(telemetry: MetricTelemetry);
  public void trackException(telemetry: ExceptionTelemetry);
  public void trackRequest(telemetry: RequestTelemetry);
  public void trackEvent(telemetry: EventTelemetry);
}
0reactions
AlexBulankoucommented, Aug 25, 2017

thoughts on a NodeClient that inherits from Client to have domain-specific objects rather than hiding them in Utils .

@OsvaldoRosado, I agree with this approach, this is how I’m doing it: https://github.com/Microsoft/ApplicationInsights-node.js/blob/albulank/trapi/Library/NodeClient.ts

Read more comments on GitHub >

github_iconTop Results From Across the Web

Refactoring API Code - API - INTERMEDIATE - Skillsoft
In this course, you'll learn about the need for refactoring, best practices, and benefits of refactoring code. You'll then examine technical debt and...
Read more >
Is there any Eclipse refactoring API that I can call ...
I know that from inside the Eclipse IDE I can refactor my classes. But is there any API that I can use in...
Read more >
Refactoring Towards Expressive REST APIs: Let Your Code ...
One of the main advantages of RESTful APIs is discoverability—clients can know what resources are available to them based on hypermedia links ...
Read more >
Refactoring source code in Visual Studio Code
Visual Studio Code supports refactoring operations (refactorings) such as Extract Method and Extract Variable to improve your code base from within your editor....
Read more >
How to refactor code when capturing calls made to an API ...
The method that takes an URI, breaks it down, creates a SQL query, and returns the rows as a PreparedStatement, used to be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found