# Send metrics in bulk POST https://app.unleash-instance.example.com/api/client/metrics/bulk Content-Type: application/json This operation accepts batched metrics from any client. Metrics will be inserted into Unleash's metrics storage Reference: https://docs.getunleash.io/api/client-bulk-metrics ## OpenAPI Specification ```yaml openapi: 3.1.1 info: title: Send metrics in bulk version: endpoint_unleashEdge.clientBulkMetrics paths: /api/client/metrics/bulk: post: operationId: client-bulk-metrics summary: Send metrics in bulk description: >- This operation accepts batched metrics from any client. Metrics will be inserted into Unleash's metrics storage tags: - - subpackage_unleashEdge parameters: - name: Authorization in: header description: Header authentication of the form `undefined ` required: true schema: type: string responses: '202': description: This response has no body. content: application/json: schema: $ref: >- #/components/schemas/Unleash Edge_clientBulkMetrics_Response_202 '400': description: The request data does not match what we expect. content: {} '413': description: >- The request body is larger than what we accept. By default we only accept bodies of 100kB or less content: {} '415': description: >- The operation does not support request payloads of the provided type. Please ensure that you're using one of the listed payload types and that you have specified the right content type in the "content-type" header. content: {} requestBody: description: bulkMetricsSchema content: application/json: schema: $ref: '#/components/schemas/bulkMetricsSchema' components: schemas: BulkRegistrationSchemaConnectViaItems: type: object properties: appName: type: string instanceId: type: string required: - appName - instanceId dateSchema: oneOf: - type: string format: date-time - type: integer BulkRegistrationSchemaSdkType: type: string enum: - value: frontend - value: backend bulkRegistrationSchema: type: object properties: connectVia: type: array items: $ref: '#/components/schemas/BulkRegistrationSchemaConnectViaItems' description: >- A list of applications this app registration has been registered through. If connected directly to Unleash, this is an empty list. This can be used in later visualizations to tell how many levels of proxy or Edge instances our SDKs have connected through appName: type: string description: The name of the application that is evaluating toggles environment: type: string description: Which environment the application is running in instanceId: type: string description: >- A [(somewhat) unique identifier](https://docs.getunleash.io/sdks/node#advanced-usage) for the application interval: type: number format: double description: How often (in seconds) the application refreshes its features started: $ref: '#/components/schemas/dateSchema' description: The application started at strategies: type: array items: type: string description: >- Enabled [strategies](https://docs.getunleash.io/concepts/activation-strategies) in the application projects: type: array items: type: string description: The list of projects used in the application sdkVersion: type: string description: The version the sdk is running. Typically : sdkType: oneOf: - $ref: '#/components/schemas/BulkRegistrationSchemaSdkType' - type: 'null' description: The sdk type required: - appName - environment - instanceId clientMetricsEnvSchema: type: object properties: featureName: type: string description: Name of the feature checked by the SDK appName: type: string description: The name of the application the SDK is being used in environment: type: string description: Which environment the SDK is being used in timestamp: $ref: '#/components/schemas/dateSchema' description: >- The start of the time window these metrics are valid for. The window is 1 hour wide 'yes': type: integer description: How many times the toggle evaluated to true 'no': type: integer description: How many times the toggle evaluated to false variants: type: object additionalProperties: type: integer description: How many times each variant was returned required: - featureName - appName - environment ImpactMetricsSchemaOneOf0Type: type: string enum: - value: counter - value: gauge ImpactMetricsSchemaOneOf0SamplesItemsLabels: oneOf: - type: string - type: number format: double ImpactMetricsSchemaOneOf0SamplesItems: type: object properties: value: type: number format: double description: The value of the metric sample labels: type: object additionalProperties: $ref: '#/components/schemas/ImpactMetricsSchemaOneOf0SamplesItemsLabels' description: Optional labels for the metric sample required: - value ImpactMetricsSchema0: type: object properties: name: type: string description: Name of the impact metric help: type: string description: Human-readable description of what the metric measures type: $ref: '#/components/schemas/ImpactMetricsSchemaOneOf0Type' description: Type of the metric samples: type: array items: $ref: '#/components/schemas/ImpactMetricsSchemaOneOf0SamplesItems' description: Samples of the numeric metric required: - name - help - type - samples ImpactMetricsSchemaOneOf1Type: type: string enum: - value: histogram ImpactMetricsSchemaOneOf1SamplesItemsBucketsItemsLe1: type: string enum: - value: +Inf ImpactMetricsSchemaOneOf1SamplesItemsBucketsItemsLe: oneOf: - type: number format: double - $ref: >- #/components/schemas/ImpactMetricsSchemaOneOf1SamplesItemsBucketsItemsLe1 ImpactMetricsSchemaOneOf1SamplesItemsBucketsItems: type: object properties: le: $ref: >- #/components/schemas/ImpactMetricsSchemaOneOf1SamplesItemsBucketsItemsLe description: Upper bound of the bucket count: type: number format: double description: Count of observations in this bucket required: - le - count ImpactMetricsSchemaOneOf1SamplesItemsLabels: oneOf: - type: string - type: number format: double ImpactMetricsSchemaOneOf1SamplesItems: type: object properties: count: type: number format: double description: Total count of observations sum: type: number format: double description: Sum of all observed values buckets: type: array items: $ref: >- #/components/schemas/ImpactMetricsSchemaOneOf1SamplesItemsBucketsItems description: Histogram buckets labels: type: object additionalProperties: $ref: '#/components/schemas/ImpactMetricsSchemaOneOf1SamplesItemsLabels' description: Optional labels for the metric sample required: - count - sum - buckets ImpactMetricsSchema1: type: object properties: name: type: string description: Name of the impact metric help: type: string description: Human-readable description of what the metric measures type: $ref: '#/components/schemas/ImpactMetricsSchemaOneOf1Type' description: Type of the metric samples: type: array items: $ref: '#/components/schemas/ImpactMetricsSchemaOneOf1SamplesItems' description: Samples of the histogram metric required: - name - help - type - samples impactMetricsSchema: oneOf: - $ref: '#/components/schemas/ImpactMetricsSchema0' - $ref: '#/components/schemas/ImpactMetricsSchema1' bulkMetricsSchema: type: object properties: applications: type: array items: $ref: '#/components/schemas/bulkRegistrationSchema' description: A list of applications registered by an Unleash SDK metrics: type: array items: $ref: '#/components/schemas/clientMetricsEnvSchema' description: >- a list of client usage metrics registered by downstream providers. (Typically Unleash Edge) impactMetrics: type: array items: $ref: '#/components/schemas/impactMetricsSchema' description: >- a list of custom impact metrics registered by downstream providers. (Typically Unleash Edge) required: - applications - metrics Unleash Edge_clientBulkMetrics_Response_202: type: object properties: {} ``` ## SDK Code Examples ```python import requests url = "https://app.unleash-instance.example.com/api/client/metrics/bulk" payload = { "applications": [ { "appName": "Ingress load balancer", "environment": "development", "instanceId": "application-name-dacb1234" } ], "metrics": [ { "featureName": "my.special.feature", "appName": "accounting", "environment": "development" } ] } headers = { "Authorization": "", "Content-Type": "application/json" } response = requests.post(url, json=payload, headers=headers) print(response.json()) ``` ```javascript const url = 'https://app.unleash-instance.example.com/api/client/metrics/bulk'; const options = { method: 'POST', headers: {Authorization: '', 'Content-Type': 'application/json'}, body: '{"applications":[{"appName":"Ingress load balancer","environment":"development","instanceId":"application-name-dacb1234"}],"metrics":[{"featureName":"my.special.feature","appName":"accounting","environment":"development"}]}' }; try { const response = await fetch(url, options); const data = await response.json(); console.log(data); } catch (error) { console.error(error); } ``` ```go package main import ( "fmt" "strings" "net/http" "io" ) func main() { url := "https://app.unleash-instance.example.com/api/client/metrics/bulk" payload := strings.NewReader("{\n \"applications\": [\n {\n \"appName\": \"Ingress load balancer\",\n \"environment\": \"development\",\n \"instanceId\": \"application-name-dacb1234\"\n }\n ],\n \"metrics\": [\n {\n \"featureName\": \"my.special.feature\",\n \"appName\": \"accounting\",\n \"environment\": \"development\"\n }\n ]\n}") req, _ := http.NewRequest("POST", url, payload) req.Header.Add("Authorization", "") req.Header.Add("Content-Type", "application/json") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := io.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` ```ruby require 'uri' require 'net/http' url = URI("https://app.unleash-instance.example.com/api/client/metrics/bulk") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true request = Net::HTTP::Post.new(url) request["Authorization"] = '' request["Content-Type"] = 'application/json' request.body = "{\n \"applications\": [\n {\n \"appName\": \"Ingress load balancer\",\n \"environment\": \"development\",\n \"instanceId\": \"application-name-dacb1234\"\n }\n ],\n \"metrics\": [\n {\n \"featureName\": \"my.special.feature\",\n \"appName\": \"accounting\",\n \"environment\": \"development\"\n }\n ]\n}" response = http.request(request) puts response.read_body ``` ```java import com.mashape.unirest.http.HttpResponse; import com.mashape.unirest.http.Unirest; HttpResponse response = Unirest.post("https://app.unleash-instance.example.com/api/client/metrics/bulk") .header("Authorization", "") .header("Content-Type", "application/json") .body("{\n \"applications\": [\n {\n \"appName\": \"Ingress load balancer\",\n \"environment\": \"development\",\n \"instanceId\": \"application-name-dacb1234\"\n }\n ],\n \"metrics\": [\n {\n \"featureName\": \"my.special.feature\",\n \"appName\": \"accounting\",\n \"environment\": \"development\"\n }\n ]\n}") .asString(); ``` ```php request('POST', 'https://app.unleash-instance.example.com/api/client/metrics/bulk', [ 'body' => '{ "applications": [ { "appName": "Ingress load balancer", "environment": "development", "instanceId": "application-name-dacb1234" } ], "metrics": [ { "featureName": "my.special.feature", "appName": "accounting", "environment": "development" } ] }', 'headers' => [ 'Authorization' => '', 'Content-Type' => 'application/json', ], ]); echo $response->getBody(); ``` ```csharp using RestSharp; var client = new RestClient("https://app.unleash-instance.example.com/api/client/metrics/bulk"); var request = new RestRequest(Method.POST); request.AddHeader("Authorization", ""); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", "{\n \"applications\": [\n {\n \"appName\": \"Ingress load balancer\",\n \"environment\": \"development\",\n \"instanceId\": \"application-name-dacb1234\"\n }\n ],\n \"metrics\": [\n {\n \"featureName\": \"my.special.feature\",\n \"appName\": \"accounting\",\n \"environment\": \"development\"\n }\n ]\n}", ParameterType.RequestBody); IRestResponse response = client.Execute(request); ``` ```swift import Foundation let headers = [ "Authorization": "", "Content-Type": "application/json" ] let parameters = [ "applications": [ [ "appName": "Ingress load balancer", "environment": "development", "instanceId": "application-name-dacb1234" ] ], "metrics": [ [ "featureName": "my.special.feature", "appName": "accounting", "environment": "development" ] ] ] as [String : Any] let postData = JSONSerialization.data(withJSONObject: parameters, options: []) let request = NSMutableURLRequest(url: NSURL(string: "https://app.unleash-instance.example.com/api/client/metrics/bulk")! as URL, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 10.0) request.httpMethod = "POST" request.allHTTPHeaderFields = headers request.httpBody = postData as Data let session = URLSession.shared let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in if (error != nil) { print(error as Any) } else { let httpResponse = response as? HTTPURLResponse print(httpResponse) } }) dataTask.resume() ```