<p>I am trying to set up <a href="https://cloud.google.com/debugger/docs/setup/go" rel="nofollow noreferrer">Stackdriver debugging</a> using Go. Using the article and this great <a href="https://medium.com/google-cloud/stackdriver-error-reporting-part-2-826f40e00886" rel="nofollow noreferrer">medium post</a> I came up with this <a href="https://github.com/roberson34/stackdriver-demo" rel="nofollow noreferrer">solution</a>.</p>

<p>Key parts, in <code>cloudbuild.yaml</code></p>

<pre><code>- name: gcr.io/cloud-builders/wget
  args: [
    "-O",
    "go-cloud-debug",
    "https://storage.googleapis.com/cloud-debugger/compute-go/go-cloud-debug"
  ]

...
</code></pre>

<p>Dockerfile I have</p>

<pre><code>...

COPY gopath/bin/stackdriver-demo /stackdriver-demo

ADD go-cloud-debug /
ADD source-context.json /

CMD ["/go-cloud-debug","-sourcecontext=./source-context.json", "-appmodule=go-errrep","-appversion=1.0","--","/stackdriver-demo"]

...

</code></pre>

<p>However the pods keeps crashing, the container logs show this error:</p>

<pre><code>Error loading program: decoding dwarf section info at offset 0x0: too short
</code></pre>

<p>EDIT: Using <code>https://storage.googleapis.com/cloud-debugger/compute-go/go-cloud-debug</code> may be outdated as I haven't seen it used outside Daz's medium post. The official <a href="https://cloud.google.com/debugger/docs/setup/go" rel="nofollow noreferrer">docs</a> uses the package <code>cloud.google.com/go/cmd/go-cloud-debug-agent</code></p>

<p>I have update cloudbuild.yaml file to install this package:</p>

<pre><code>- name: 'gcr.io/cloud-builders/go'
  args: ["get", "-u", "cloud.google.com/go/cmd/go-cloud-debug-agent"]
  env: ['PROJECT_ROOT=github.com/roberson34/stackdriver-demo', 'CGO_ENABLED=0', 'GOOS=linux']

- name: 'gcr.io/cloud-builders/go'
  args: ["install", "cloud.google.com/go/cmd/go-cloud-debug-agent"]
  env: ['PROJECT_ROOT=github.com/roberson34/stackdriver-demo', 'CGO_ENABLED=0', 'GOOS=linux']
</code></pre>

<p>And in the <code>Dockerfile</code> I can get access to the binary in <code>gopath/bin/go-cloud-debug-agent</code></p>

<p>When I execute the <code>gopath/bin/go-cloud-debug-agent</code> with my own program as an argument:</p>

<p><code>/go-cloud-debug-agent -sourcecontext=./source-context.json -appmodule=go-errrep -appversion=1.0 -- /stackdriver-demo</code></p>

<p>I get another opaque error: </p>

<pre><code>Error loading program: AttrStmtList not present or not int64 for unit 88
</code></pre>

<p>So basically using the <code>cloud-debug</code> binary from <code>https://storage.googleapis.com/cloud-debugger/compute-go/go-cloud-debug</code> and <code>cloud-debug-agent</code> binary from the package <code>cloud.google.com/go/cmd/go-cloud-debug-agent</code> both don't work and give different errors.</p>

<p>Would appreciate any tips on what I'm doing wrong and how to fix it.</p>

robertson
<p>OK :-)</p>

<p>Yes, you should follow the current Stackdriver documentation, e.g. <code>go-cloud-debug-agent</code></p>

<p>Unfortunately, there are now various issues with my post including a (currently broken) <code>gcr.io/cloud-builders/kubectl</code> for regions.</p>

<p>I think your issue pertains to your use of <code>golang:alpine</code>. Alpine uses musl rather than the glibc that you find on most other Linux distro's and so, you really must compile for Alpine to ensure your binaries reference the correct libc.</p>

<p>I'm able to get your solution working <em>primarily</em> by switching your Dockerfile to pull the Cloud Debug Agent while on Alpine and to compile your source on Alpine:</p>

<pre><code>FROM golang:alpine

RUN apk add git
RUN go get -u cloud.google.com/go/cmd/go-cloud-debug-agent

ADD main.go src
RUN CGO_ENABLED=0 go build -gcflags=all='-N -l' src/main.go

ADD source-context.json /

CMD ["bin/go-cloud-debug-agent","-sourcecontext=/source-context.json", "-appmodule=stackdriver-demo","-appversion=1.0","--","main"]

</code></pre>

<p>I think that should get you beyond the errors that you documented and you should be able to deploy your container to Kubernetes.</p>

<p>I've made my version of your image publicly available (and will retain it for a few days for you):</p>

<pre><code>gcr.io/dazwilkin-190402-55473323/roberson34@sha256:17cb45f1320e2fe04e0681310506f4c229896429192b0d1c2c8dc20ed54adb0d
</code></pre>

<p>You may wish to reference it (by that digest) in your <code>deployment.yaml</code></p>

<p><strong>NB</strong> For Error Reporting to be "interesting", your code needs to generate errors and, with your example, this is going to be challenging (usually a good thing). You may consider adding another errorful handler that always results in errors so that you may test the service.</p>
