Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Go-Linter

on:
pull_request:
branches:
- main
- develop
permissions:
contents: read
pull-requests: read
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: latest

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
args: --verbose

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

# Optional: if set to true then the action will use pre-installed Go.
# skip-go-installation: true

# Optional: if set to true then the action don't cache or restore ~/go/pkg.
# skip-pkg-cache: true

# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
# skip-build-cache: true

Unit-testing:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run tests
uses: actions/setup-go@v2
with:
go-version: 1.18

- name: Test script
run: go test ./...

10 changes: 10 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Configuraciones para el linter de Golang-ci
run:
go: '1.18'
# Desactivando linters para Go-18
linters:
disable:
- gosimple
- staticcheck
- structcheck
- unused
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
language: go

go:
- 1.12.x
- 1.13.x
- 1.14.x
- 1.15.x

sudo: false

Expand Down
71 changes: 37 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Microsoft Application Insights SDK for Go
# Application Insights SDK for Go


[![Build Status](https://travis-ci.org/Microsoft/ApplicationInsights-Go.svg?branch=master)](https://travis-ci.org/Microsoft/ApplicationInsights-Go) [![Documentation](https://godoc.org/github.com/microsoft/ApplicationInsights-Go?status.svg)](https://godoc.org/github.com/microsoft/ApplicationInsights-Go/appinsights) [![Release](https://img.shields.io/github/release/Microsoft/ApplicationInsights-Go/all.svg)](https://github.com/microsoft/ApplicationInsights-Go/releases)

This project provides a Go SDK for Application Insights.
[Application Insights](http://azure.microsoft.com/en-us/services/application-insights/)
Expand All @@ -10,24 +10,27 @@ telemetry of various kinds (event, metric, trace) to the Application
Insights service where they can be visualized in the Azure Portal.

## Status
This SDK is NOT maintained or supported by Microsoft even though we've contributed to it in the past. Note that Azure Monitor only provides support when using our [supported SDKs](https://docs.microsoft.com/en-us/azure/azure-monitor/app/platforms#unsupported-community-sdks), and this SDK does not yet meet that standard. Known gaps include:

* Operation correlation is not supported, but this can be managed by the
caller through the interfaces that exist today.
* Sampling is not supported. The more mature SDKs support dynamic sampling,
but at present this does not even support manual sampling.
* Automatic collection of events is not supported. All telemetry must be
explicitly collected and sent by the user.
* Offline storage of telemetry is not supported. The .Net SDK is capable of
spilling events to disk in case of network interruption. This SDK has no
such feature.
This is a fork from the original [Microsoft project](https://github.com/javestmx/geecommon).

This SDK is NOT currently maintained or supported by Microsoft. Azure Monitor only provides support when using our [supported SDKs](https://docs.microsoft.com/en-us/azure/azure-monitor/app/platforms#unsupported-community-sdks).


## Contrubuting

Please feel free to fork this project and submit any pull requests.

Submitting pull requests will solve issues faster than just reporting them. Taking
acctions is always usefull than cry and wait for someone else solution.

## Dislclaimer

We’re constantly assessing opportunities to expand our support for other languages, so follow our [GitHub Announcements](https://github.com/microsoft/ApplicationInsights-Announcements/issues) page to receive the latest SDK news.
JAVEST or any developer who contributes to this repo are not responsible for any damages or losses caused by using this SDK. Use at your own risk.

## Requirements
**Install**
```
go get github.com/microsoft/ApplicationInsights-Go/appinsights
go get github.com/javestmx/ApplicationInsights-Go
```
**Get an instrumentation key**
>**Note**: an instrumentation key is required before any data can be sent. Please see the "[Getting an Application Insights Instrumentation Key](https://github.com/microsoft/AppInsights-Home/wiki#getting-an-application-insights-instrumentation-key)" section of the wiki for more information. To try the SDK without an instrumentation key, set the instrumentationKey config value to a non-empty string.
Expand All @@ -37,23 +40,23 @@ go get github.com/microsoft/ApplicationInsights-Go/appinsights
## Setup

To start tracking telemetry, you'll want to first initialize a
[telemetry client](https://godoc.org/github.com/microsoft/ApplicationInsights-Go/appinsights#TelemetryClient).
[telemetry client](https://godoc.org/github.com/javestmx/geecommon/appinsights#TelemetryClient).

```go
import "github.com/microsoft/ApplicationInsights-Go/appinsights"
import "github.com/javestmx/ApplicationInsights-Go"

func main() {
client := appinsights.NewTelemetryClient("<instrumentation key>")
}
```

If you want more control over the client's behavior, you should initialize a
new [TelemetryConfiguration](https://godoc.org/github.com/microsoft/ApplicationInsights-Go/appinsights#TelemetryConfiguration)
new [TelemetryConfiguration](https://godoc.org/github.com/javestmx/geecommon/appinsights#TelemetryConfiguration)
object and use it to create a client:

```go
import "time"
import "github.com/microsoft/ApplicationInsights-Go/appinsights"
import "github.com/javestmx/ApplicationInsights-Go"

func main() {
telemetryConfig := appinsights.NewTelemetryConfiguration("<instrumentation key>")
Expand All @@ -76,7 +79,7 @@ it in your data model.

## Telemetry submission

The [TelemetryClient](https://godoc.org/github.com/microsoft/ApplicationInsights-Go/appinsights#TelemetryClient)
The [TelemetryClient](https://godoc.org/github.com/javestmx/geecommon/appinsights#TelemetryClient)
itself has several methods for submitting telemetry:

```go
Expand Down Expand Up @@ -128,7 +131,7 @@ then be submitted through the `TelemetryClient.Track` method, as illustrated
in the below sections:

### Trace
[Trace telemetry items](https://godoc.org/github.com/microsoft/ApplicationInsights-Go/appinsights#TraceTelemetry)
[Trace telemetry items](https://godoc.org/github.com/javestmx/ApplicationInsights-Go/appinsights#TraceTelemetry)
represent printf-like trace statements that can be text searched. They have
an associated severity level, values for which are found in the package's
constants:
Expand Down Expand Up @@ -160,7 +163,7 @@ client.Track(trace)
```

### Events
[Event telemetry items](https://godoc.org/github.com/microsoft/ApplicationInsights-Go/appinsights#EventTelemetry)
[Event telemetry items](https://godoc.org/github.com/javestmx/ApplicationInsights-Go/appinsights#EventTelemetry)
represent structured event records.

```go
Expand All @@ -170,7 +173,7 @@ client.Track(event)
```

### Single-value metrics
[Metric telemetry items](https://godoc.org/github.com/microsoft/ApplicationInsights-Go/appinsights#MetricTelemetry)
[Metric telemetry items](https://godoc.org/github.com/javestmx/ApplicationInsights-Go/appinsights#MetricTelemetry)
each represent a single data point.

```go
Expand All @@ -182,7 +185,7 @@ client.Track(metric)
### Pre-aggregated metrics
To reduce the number of metric values that may be sent through telemetry,
when using a particularly high volume of measurements, metric data can be
[pre-aggregated by the client](https://godoc.org/github.com/microsoft/ApplicationInsights-Go/appinsights#AggregateMetricTelemetry)
[pre-aggregated by the client](https://godoc.org/github.com/javestmx/ApplicationInsights-Go/appinsights#AggregateMetricTelemetry)
and submitted all at once.

```go
Expand Down Expand Up @@ -215,7 +218,7 @@ client.Track(aggregate)
```

### Requests
[Request telemetry items](https://godoc.org/github.com/microsoft/ApplicationInsights-Go/appinsights#RequestTelemetry)
[Request telemetry items](https://godoc.org/github.com/javestmx/ApplicationInsights-Go/appinsights#RequestTelemetry)
represent completion of an external request to the application and contains
a summary of that request execution and results. This SDK's request
telemetry is focused on HTTP requests.
Expand Down Expand Up @@ -250,7 +253,7 @@ client.Track(request)
```

### Dependencies
[Remote dependency telemetry items](https://godoc.org/github.com/microsoft/ApplicationInsights-Go/appinsights#RemoteDependencyTelemetry)
[Remote dependency telemetry items](https://godoc.org/github.com/javestmx/ApplicationInsights-Go/appinsights#RemoteDependencyTelemetry)
represent interactions of the monitored component with a remote
component/service like SQL or an HTTP endpoint.

Expand Down Expand Up @@ -281,7 +284,7 @@ client.Track(dependency)
```

### Exceptions
[Exception telemetry items](https://godoc.org/github.com/microsoft/ApplicationInsights-Go/appinsights#ExceptionTelemetry)
[Exception telemetry items](https://godoc.org/github.com/javestmx/ApplicationInsights-Go/appinsights#ExceptionTelemetry)
represent handled or unhandled exceptions that occurred during the execution
of the monitored application. This SDK is geared towards handling panics or
unexpected results from important functions:
Expand Down Expand Up @@ -353,7 +356,7 @@ if err != nil {
```

### Availability
[Availability telemetry items](https://godoc.org/github.com/microsoft/ApplicationInsights-Go/appinsights/#AvailabilityTelemetry)
[Availability telemetry items](https://godoc.org/github.com/javestmx/ApplicationInsights-Go/appinsights/#AvailabilityTelemetry)
represent the result of executing an availability test. This is useful if
you are writing availability monitors in Go.

Expand All @@ -378,7 +381,7 @@ client.Track(availability)
```

### Page Views
[Page view telemetry items](https://godoc.org/github.com/microsoft/ApplicationInsights-Go/appinsights/#PageViewTelemetry)
[Page view telemetry items](https://godoc.org/github.com/javestmx/ApplicationInsights-Go/appinsights/#PageViewTelemetry)
represent generic actions on a page like a button click. These are typically
generated by the client side rather than the server side, but is available
here nonetheless.
Expand All @@ -399,10 +402,10 @@ client.Track(pageview)
Telemetry items all have a `Tags` property that contains information *about*
the submitted telemetry, such as user, session, and device information. The
`Tags` property is an instance of the
[contracts.ContextTags](https://godoc.org/github.com/microsoft/ApplicationInsights-Go/appinsights/contracts/#ContextTags)
[contracts.ContextTags](https://godoc.org/github.com/javestmx/ApplicationInsights-Go/appinsights/contracts/#ContextTags)
type, which is a `map[string]string` under the hood, but has helper methods
to access the most commonly used data. An instance of
[TelemetryContext](https://godoc.org/github.com/microsoft/ApplicationInsights-Go/appinsights/#TelemetryContext)
[TelemetryContext](https://godoc.org/github.com/javestmx/ApplicationInsights-Go/appinsights/#TelemetryContext)
exists on the `TelemetryClient`, and also contains a `Tags` property. These
tags are applied to all telemetry sent through the client. If a context tag
is found on both the client's `TelemetryContext` and in the telemetry item's
Expand All @@ -414,8 +417,8 @@ A few examples for illustration:
import (
"os"

"github.com/microsoft/ApplicationInsights-Go/appinsights"
"github.com/microsoft/ApplicationInsights-Go/appinsights/contracts"
"github.com/javestmx/ApplicationInsights-Go/appinsights"
"github.com/javestmx/ApplicationInsights-Go/appinsights/contracts"
)

func main() {
Expand Down Expand Up @@ -461,7 +464,7 @@ func main() {
```

### Shutdown
The Go SDK submits data asynchronously. The [InMemoryChannel](https://godoc.org/github.com/microsoft/ApplicationInsights-Go/appinsights/#InMemoryChannel)
The Go SDK submits data asynchronously. The [InMemoryChannel](https://godoc.org/github.com/javestmx/ApplicationInsights-Go/appinsights/#InMemoryChannel)
launches its own goroutine used to accept and send telemetry. If you're not
careful, this may result in lost telemetry when the service needs to shut
down. The channel has a few methods to deal with this case:
Expand Down Expand Up @@ -509,7 +512,7 @@ func main() {

We recommend something similar to the above to minimize lost telemetry
through shutdown.
[The documentation](https://godoc.org/github.com/microsoft/ApplicationInsights-Go/appinsights#TelemetryChannel)
[The documentation](https://godoc.org/github.com/javestmx/ApplicationInsights-Go/appinsights#TelemetryChannel)
explains in more detail what can lead to the cases above.

### Diagnostics
Expand Down
2 changes: 1 addition & 1 deletion appinsights/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package appinsights
import (
"time"

"github.com/microsoft/ApplicationInsights-Go/appinsights/contracts"
"github.com/javestmx/ApplicationInsights-Go/appinsights/contracts"
)

// Application Insights telemetry client provides interface to track telemetry
Expand Down
4 changes: 2 additions & 2 deletions appinsights/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package appinsights
import (
"bytes"
"compress/gzip"
"io/ioutil"
"io"
"testing"
"time"
)
Expand Down Expand Up @@ -93,7 +93,7 @@ func TestEndToEnd(t *testing.T) {
}

// Read payload
body, err := ioutil.ReadAll(reader)
body, err := io.ReadAll(reader)
reader.Close()
if err != nil {
t.Fatalf("Couldn't read compressed data: %s", err.Error())
Expand Down
2 changes: 1 addition & 1 deletion appinsights/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package appinsights

// NOTE: This file was automatically generated.

import "github.com/microsoft/ApplicationInsights-Go/appinsights/contracts"
import "github.com/javestmx/ApplicationInsights-Go/appinsights/contracts"

// Type of the metric data measurement.
const (
Expand Down
2 changes: 1 addition & 1 deletion appinsights/exception.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"runtime"
"strings"

"github.com/microsoft/ApplicationInsights-Go/appinsights/contracts"
"github.com/javestmx/ApplicationInsights-Go/appinsights/contracts"
)

// Exception telemetry items represent a handled or unhandled exceptions that
Expand Down
2 changes: 1 addition & 1 deletion appinsights/exception_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"
"testing"

"github.com/microsoft/ApplicationInsights-Go/appinsights/contracts"
"github.com/javestmx/ApplicationInsights-Go/appinsights/contracts"
)

type myStringer struct{}
Expand Down
2 changes: 1 addition & 1 deletion appinsights/inmemorychannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"time"

"code.cloudfoundry.org/clock"
"github.com/microsoft/ApplicationInsights-Go/appinsights/contracts"
"github.com/javestmx/ApplicationInsights-Go/appinsights/contracts"
)

var (
Expand Down
8 changes: 4 additions & 4 deletions appinsights/inmemorychannel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,10 +404,10 @@ func TestPartialRetry(t *testing.T) {
ItemsAccepted: 2,
ItemsReceived: 5,
Errors: []*itemTransmissionResult{
&itemTransmissionResult{Index: 1, StatusCode: 500, Message: "Server Error"},
&itemTransmissionResult{Index: 2, StatusCode: 200, Message: "OK"},
&itemTransmissionResult{Index: 3, StatusCode: 400, Message: "Bad Request"},
&itemTransmissionResult{Index: 4, StatusCode: 408, Message: "Plz Retry"},
{Index: 1, StatusCode: 500, Message: "Server Error"},
{Index: 2, StatusCode: 200, Message: "OK"},
{Index: 3, StatusCode: 400, Message: "Bad Request"},
{Index: 4, StatusCode: 408, Message: "Plz Retry"},
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion appinsights/jsonserializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"

"github.com/microsoft/ApplicationInsights-Go/appinsights/contracts"
"github.com/javestmx/ApplicationInsights-Go/appinsights/contracts"
)

type telemetryBufferItems []*contracts.Envelope
Expand Down
2 changes: 1 addition & 1 deletion appinsights/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ package appinsights

const (
sdkName = "go"
Version = "0.4.3"
Version = "0.4.4"
)
2 changes: 1 addition & 1 deletion appinsights/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strconv"
"time"

"github.com/microsoft/ApplicationInsights-Go/appinsights/contracts"
"github.com/javestmx/ApplicationInsights-Go/appinsights/contracts"
)

// Common interface implemented by telemetry data contracts
Expand Down
Loading