Documentation ¶
Index ¶
Examples ¶
Constants ¶
const (
ServiceNameIngestion cloud.ServiceName = "ingestion/azlogs"
)
Cloud Service Names for Monitor Ingestion, used to identify the respective cloud.ServiceConfiguration
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client contains the methods for the Client group. Don't use this type directly, use a constructor function instead.
func NewClient ¶
func NewClient(endpoint string, credential azcore.TokenCredential, options *ClientOptions) (*Client, error)
NewClient creates a client to upload logs to Azure Monitor Ingestion.
Example ¶
endpoint = os.Getenv("DATA_COLLECTION_ENDPOINT") cred, err := azidentity.NewDefaultAzureCredential(nil) if err != nil { //TODO: handle error } client, err := azlogs.NewClient(endpoint, cred, nil) if err != nil { //TODO: handle error } _ = client
Output:
func (*Client) Upload ¶
func (client *Client) Upload(ctx context.Context, ruleID string, streamName string, logs []byte, options *UploadOptions) (UploadResponse, error)
Upload - Ingestion API used to directly ingest data using Data Collection Rules. Maximum size of of API call is 1 MB. If the operation fails it returns an *azcore.ResponseError type.
Generated from API version 2023-01-01
- ruleID - The immutable Id of the Data Collection Rule resource.
- streamName - The streamDeclaration name as defined in the Data Collection Rule.
- logs - An array of objects matching the schema defined by the provided stream.
- options - UploadOptions contains the optional parameters for the Client.Upload method.
Example ¶
package main import ( "context" "encoding/json" "os" "strconv" "time" "github.com/Azure/azure-sdk-for-go/sdk/monitor/ingestion/azlogs" ) var client azlogs.Client type Computer struct { Time time.Time Computer string AdditionalContext string } func main() { // set necessary data collection rule variables ruleID := os.Getenv("DATA_COLLECTION_RULE_IMMUTABLE_ID") streamName := os.Getenv("DATA_COLLECTION_RULE_STREAM_NAME") // generating logs // logs should match the schema defined by the provided stream var data []Computer for i := 0; i < 10; i++ { data = append(data, Computer{ Time: time.Now().UTC(), Computer: "Computer" + strconv.Itoa(i), AdditionalContext: "context", }) } // Marshal data into []byte logs, err := json.Marshal(data) if err != nil { panic(err) } // upload logs _, err = client.Upload(context.TODO(), ruleID, streamName, logs, nil) if err != nil { //TODO: handle error } }
Output:
type ClientOptions ¶
type ClientOptions struct {
azcore.ClientOptions
}
ClientOptions contains optional settings for Client.
type UploadOptions ¶
type UploadOptions struct { // If the bytes of the "logs" parameter are already gzipped, set ContentEncoding to "gzip" ContentEncoding *string }
UploadOptions contains the optional parameters for the Client.Upload method.
type UploadResponse ¶
type UploadResponse struct { }
UploadResponse contains the response from method Client.Upload.