newrelic / infra-integrations-sdk

New Relic Infrastructure Integrations SDK
Apache License 2.0
44 stars 23 forks source link

invalid character '\\'' looking for beginning of object key string #303

Closed rmarops closed 1 year ago

rmarops commented 1 year ago

Description

I am unable to decipher what string formatting is unacceptable

Steps to Reproduce

this is the output from my program, it is just mock up output for now: {"integration_version":"0.1.0","protocol_version":"2","data":[{"metrics":[{"some-data":4000,"event_type":"CustomSample"}],"inventory":{"instance":{"version":"3.0.1"}},"events":[{"category":"status","summary":"restart"}]}],"name":"com.myorganization.svctest"}

Your Environment

Amazon Linux2

Additional context

May 31 15:20:17 ip-10-0-0-224.ec2.internal newrelic-infra-service[3961]: time="2023-05-31T15:20:17Z" level=warning msg="Cannot emit integration payload" component=integrations.runner.Runner error="invalid character '\'' looking for beginning of object key string" integration_name=svctest payload="{'integration_version': '0.1.0', 'protocol_version': '2', 'data': [{'metrics': [{'some-data': 4000, 'event_type': 'CustomSample'}], 'inventory': {'instance': {'version': '3.0.1'}}, 'events': [{'category': 'status', 'summary': 'restart'}]}], 'name': 'com.myorganization.svctest'}" runner_uid=89e32cfcbd

For Maintainers Only or Hero Triaging this bug

Suggested Priority (P1,P2,P3,P4,P5): Suggested T-Shirt size (S, M, L, XL, Unknown):

workato-integration[bot] commented 1 year ago

https://issues.newrelic.com/browse/NEWRELIC-8871

alvarocabanas commented 1 year ago

Hello, I have tried creating a simple go binary mocking the response you comment:

package main

import (
    "fmt"
)

func main() {
    fmt.Println(`{"integration_version":"0.1.0","protocol_version":"2","data":[{"metrics":[{"some-data3":4000,"event_type":"CustomSample"}],"inventory":{"instance":{"version":"3.0.1"}},"events":[{"category":"status","summary":"restart"}]}],"name":"com.myorganization.svctest"}`)
}

I build it as nri-custom, and it gets correctly computed by the agent when setting it up in the integrations configuration:

integrations:
  - name: nri-custom
    labels:
      environment: staging

The same applies when creating the binary using the SDK:

package main

import (
    "github.com/newrelic/infra-integrations-sdk/data/metric"
    "github.com/newrelic/infra-integrations-sdk/integration"
    "github.com/newrelic/infra-integrations-sdk/log"
)

var (
    integrationVersion = "0.0.0"
)

const (
    integrationName = "custom"
)

func main() {
    i, err := integration.New(integrationName, integrationVersion)
    fatalIfErr(err)

    e := i.LocalEntity()
    fatalIfErr(err)

    if err := e.Inventory.SetItem("instance", "version", "3.0.1"); err != nil {
        log.Error("fail to set inventory item: %s", err)
    }

    ms := e.NewMetricSet("CustomSample")
    err = ms.SetMetric("some-data", 4000, metric.GAUGE)
    fatalIfErr(err)

    fatalIfErr(i.Publish())
}

func fatalIfErr(err error) {
    if err != nil {
        log.Fatal(err)
    }
}

So, the payload is a valid JSON but maybe there are some extra characters on your output that are causing the error.

rmarops commented 1 year ago

thanks for the support