Skip to main content

Hey,

Im trying to get evaluation for a feature flag i defined and im encountering a few issues.

This is the code im trying to execute:

	// Get deployment key from environment variable or use a default
deploymentKey := "<MY_DEPLOYMENT_KEY>"


// Initialize the Amplitude Experiment client
client := local.Initialize(deploymentKey, nil)

// Start the client
if err := client.Start(); err != nil {
fmt.Printf("Warning: Error starting client: %v\n", err)
return
}

// Example user for feature flag evaluation
user := &experiment.User{
UserId: "user123",
DeviceId: "device456",
UserProperties: map[string]interface{}{
"userType": "premium",
"region": "US",
},
}

// Example: Evaluate feature flags
flagKeys := []string{"new-feature-flag", "feature-1", "feature-2"}
variants, err := client.EvaluateV2(user, flagKeys)
if err != nil {
fmt.Printf("Error evaluating flags: %v\n", err)
fmt.Printf("Error type: %T\n", err)
return
}

fmt.Printf("Feature flags evaluation results:\n")

and i got the following error:

Warning: Error starting client: Get "https://api.lab.amplitude.com/sdk/v2/flags?v=0": dial tcp: lookup api.lab.amplitude.com: no such host

 

I than defined the client as follows:

client := local.Initialize(deploymentKey, &local.Config{

ServerZone: local.EUServerZone,

})

 

and got an the following error:

Failed to fetch flag configs: invalid character 'I' looking for beginning of value

 

After a short debugging session in the Amplitude experiment Go SDK, i discovered that the response actually return 

Invalid Api-Key

 

Even though im definitely using the right credentials

Hi Shahar,

Thank you for reaching out! I understand you’re encountering issues with the Go SDK for evaluating feature flags, specifically the 'no such host' and 'Invalid Api-Key' errors. Let’s work through these together.


### Addressing the 'no such host' error:
This error typically occurs when the SDK cannot resolve the hostname `api.lab.amplitude.com`. Here are a few steps to troubleshoot:

1. **Network Configuration**: Ensure that your network allows access to `api.lab.amplitude.com`. Sometimes, firewalls or ad blockers can prevent the SDK from connecting.
2. **DNS Resolution**: Verify that your DNS settings are correctly resolving the hostname. You can test this by running a `ping` or `nslookup` command for `api.lab.amplitude.com`.
3. **Server Zone Configuration**: Since you’re using the `local.Config` with `ServerZone: local.EUServerZone`, ensure that your deployment key corresponds to the EU server zone. If the deployment key is for a different region, this mismatch could cause connectivity issues.

### Addressing the 'Invalid Api-Key' error:
This error suggests that the deployment key provided during initialization might not be recognized. Please check the following:

1. **Correct Deployment Key**: Double-check that the deployment key matches the one assigned to your project in the Amplitude Experiment UI. You can find this key under the 'Deployments' section.
2. **Active Deployment**: Ensure that the deployment associated with your key is active and linked to the feature flags you’re trying to evaluate.
3. **Flag Configuration**: Verify that the feature flags you’re evaluating are enabled for the correct deployment. You can review this in the Feature Flag Rollouts documentation.

### Debugging Checklist:
Here are additional points to confirm:

- Is the Experiment SDK loading after the Analytics SDK? The Experiment SDK must load after the Analytics SDK for proper initialization.
- Are the feature flags active and assigned to the correct user segments? You can check this in the Experiment UI.
- Is the request to `api.lab.amplitude.com` being blocked by any browser extensions or network settings?

### Next Steps:
If the above steps do not resolve the issue, could you provide the following details to help us investigate further?

1. The exact deployment key you’re using (please redact sensitive information).
2. A link to the feature flag(s) you’ve created in the Amplitude Experiment UI.
3. Any additional logs or stack traces related to the errors.
For more information on setting up and troubleshooting feature flags, you can refer to the Experiment Quick Start guide and the Performance and Caching documentation.

Let me know if you need further assistance or clarification on any of the steps above!

Best,
Jake


P.S. Checkout upcoming events and user meetups on our events page.

Reply